rust


Simplify a long namespace for impl when importing the type would introduce ambiguity?


Is there a way to simplify namespace for the following code?
struct T {...}
impl<'a> From<A::B::C::D::Foo<'a>> for T {
fn from(x: A::B::C::D::Foo<'a>) -> Self {
T {...}
}
}
I don't want to use A::B::C::D::Foo in the current module as Foo might bring in namespace ambiguity.
Is there a way to temporarily/locally use A::B::C::D::Foo for the impl? It seems I can only do that within a function scope, rather than an impl scope.
Currently, my workaround is to use a dummy module.
struct T {...}
mod abc {
use super::T;
use A::B::C::D::Foo;
impl<'a> From<Foo<'a>> for T {
fn from(x: Foo<'a>) -> Self {
T {...}
}
}
}
If using a nested module is the canonical solution, is it possible to define an anonymous module since the module name is unimportant?
as Foo might bring in namespace ambiguity
You can rename the type when you import it to avoid ambiguity:
pub mod a {
pub mod b {
pub mod c {
pub mod d {
pub struct Foo;
}
}
}
}
struct T;
use a::b::c::d::Foo as UniqueName;
impl<'a> From<UniqueName> for T {
fn from(_: UniqueName) -> Self {
T
}
}
fn main() {}
You could also use a type alias:
type UniqueName = a::b::c::d::Foo;

Related Links

Assign value from match statement
Why does unsafe code compile, but similar code that pushes to a vector complains that a reference doesn't live long enough?
How can I find a subsequence in a &[u8] slice?
Safe way to push the local value into a static mut
Is there a way to detect the compiler version from within a Rust program?
Modifying a Mutex<Option<>>
How can I implement Ord when the comparison depends on data not part of the compared items?
Rust Documentation Test unresolved name [duplicate]
How to convert a boxed array into a Vec in Rust
Rust executable linking to a system library works, but a library has unresolved references
mismatches between str and string
How to share mutable state for a Hyper handler?
Error: closure requires unique access to `self` but `self` is already borrowed
How can the state be shared between the returned result and the next iteration when using the scan iterator?
How do I duplicate a &[u8] slice?
Is `mem::swap`ing a `Mutex<T>` really safe?

Categories

HOME
cocoapods
hpoo
opengl
oracle
ionic2
azure-functions
automapper
adfs3.0
selenium-builder
swi-prolog
foaf
compilation
plaid
out-of-memory
ios-simulator
qooxdoo
tfs2015
impala
onvif
gtk
clickable-image
watch-os-3
nsstring
vimeo
jodatime
asp.net-core-1.0
varnish-vcl
cloudsim
renderscript
spring-shell
akka-persistence
kamailio
conda
animated-gif
fusetools
sales
appcode
nest
restful-architecture
keyboard-layout
formsauthenticationticket
testlink
installanywhere
forms-authentication
macports
uivisualeffectview
vb.net-to-c#
access-denied
windows-media-player
tinyioc
django-static-precompiler
watir-webdriver
nslayoutconstraint
wikimapia
mechanicalturk
rustdoc
http4s
yui3
dcount
eclemma
adp
android-syncadapter
processor
polymerfire
taco
certificate-authority
ioexception
servicestack-bsd
self
mousehover
lowercase
asp.net-web-api-helppages
screen-orientation
replicaset
ocmockito
rfc5545
mojo
nhibernate-criteria
fasterxml
string.format
adwords-apiv201402
inputbox
multivariate-testing
accessory
mfmessagecomposeview
csslint
sqlbindparameter
air-native-extension
xmi
oxygene
proxy-server
autonumber
smips
jmenubar
rautomation
viewpagerindicator
zotonic
prototypal-inheritance
navigationcontroller
sigar
differentiation
glassfish-esb
nsrangeexception
page-curl
digiflow
resharper-5.1
3-tier
wmd-editor
fxruby
iphone-sdk-3.1.3

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile