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

Unsafe references to attributes of the same struct
How are lifetimes of struct arguments treated in calls to functions with lifetime parameters?
Why did Rust remove the green-threading model; what's the disadvantage?
Return local String as a slice (&str)
error: The requirement is only added
Temporarily move out of borrowed content
Why does sorting take so long?
Use reference to new struct in the struct initializer
Linking the lifetimes of self and a reference in method
iterator find - referencing the needle instead of dereferencing the iterating item
Is there a way to implement a custom enumerate method?
How do you document function arguments?
Mutate an array through a window
What is the difference between len() and count()?
How can I add strings and print them?
Type annotation required when using `as_ref()` in `assert_eq!()`

Categories

HOME
php
webview
extjs
automapper
blast
gaming
key
add-on
jersey-2.0
iptables
video-streaming
javafx-8
kurento
stack-overflow
lc3
xamarin-zebble
watch-os-3
graphdb
circleci
sonata
distributed-computing
synthesis
tomcat8
word2vec
string-formatting
activeadmin
mime-types
router
multi-dimensional-scaling
miniprofiler
tsung
splunk-query
premake
commonsware-cwac
python-2.x
opnet
identify
best-buy-api
python-jira
get-event-store
data-uri
angular-datatables
vesta
cloudwatch
nonlinear-functions
karabiner
mura
sesame
degrees
finder
nitrousio
researchkit
system.net.mail
traversable
cdo.message
ajaxmin
wicked-pdf
django-redis
gwt-syncproxy
openmrs
certificate-authority
ngcordova
erlog
scala-swing
symja
utf8-decode
object-code
quantify
aho-corasick
accountmanager
windows-taskbar
strcmp
compiler-flags
grails-2.3
notin
web-frameworks
ui-design
cmath
contextswitchdeadlock
handshake
jzmq
getopts
kohana-auth
printqueue
android-2.1-eclair
mongrel
icicles
getimagesize
google-translator-toolkit
.net-client-profile
levels
jvm-bytecode

Resources

Encrypt Message