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

lifetime of Option.map's function argument
Using T from Option<T> as function parameter in Rust
References and lifetimes
Returning object containing references in Rust
Exhaustive integer matching
Index and IndexMut implementations to return borrowed vectors
Is it possible to have a Closure/Function as a member of a struct?
Why “explicit lifetime bound required” for Box<T> in struct?
Do I need any of the *variantType markers?
Cargo: invalid character `.` in crate name
Is it possible to split an impl into different modules?
Problems building rust-http in rust-openssl
How to clear the Cargo cache?
Where to put static Library?
What is the preferred way to byte swap values in Rust?
println! doesn't work in Rust unit tests?

Categories

HOME
qt
mod-rewrite
macos-sierra
generics
eclipse-plugin
android-fragments
compilation
subdomain
slider
autocomplete
tabs
mosquitto
wagtail
port
twitter-oauth
phpstorm-2017.1
buffer
ex
smartgwt
hidden
cocos2d-android
office-ui-fabric
gmp
cpu-usage
adobe-illustrator
libgit2
amazon-sns
web-config-transform
sparkle
microprocessors
region
matlab-app-designer
premake
appcode
sca
om-next
counting
apptentive
bluemixtools
testlink
spinner
love2d
ms-solver-foundation
installanywhere
ms-dos
aurelia-http-client
fiware-wirecloud
notesview
julius-speech
realstudio
.net-micro-framework
ssi
test-data
clrs
rustdoc
thread-exceptions
tsqlt
static-methods
gnucash
processor
jeasyui
android-mapview
variable-length-array
ibm-was
http.client
enaml
green-threads
bootstrap-wysiwyg
ipod
kotlin-android-extensions
shell-extensions
camus
nhibernate-criteria
jcheckbox
famo.us
password-recovery
image-rotation
berkeley-db-xml
webmethod
nachos
jini
preorder
ivalueconverter
sunstudio
sly-scroller
oscilloscope
cmath
2d-vector
icenium
taskkill
zotonic
autosize
prototypal-inheritance
kolite
fbml
servercontrol
getopts
servlet-container
qcar-sdk
mygeneration
cassini
3-tier
.net-services
yahoo-maps
dm
wmd-editor
data-retrieval
html-generation

Resources

Encrypt Message