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

Return Traits from function
Lifetime for a From trait implementation
Object safety and trait inheritance [duplicate]
How do I specify that a function takes a HashMap?
Cannot implement quickchecks Arbitrary for my own type - “source trait is private”
Returning the T borrowed from RefCell<T>
Trait implementing Sized
Are unique object ids tracked and can we print them?
How can I specify lifetimes in associated types?
What's the best way to mutate a nested enum?
Mutating the same data in multiple 'static closures
Return value is a “unresolved name”
Implementing struct that has lifetimes
Where does the Rust 1.0 Mac OS X pkg installer install to?
Want to add to HashMap using pattern match, get borrow mutable more than once at a time
Is it possible to check if an object implements a trait at runtime?

Categories

HOME
user-interface
protocol-buffers
apache-nifi
yii
stacktrace.js
plaid
mongoid
vue-resource
impala
stored-procedures
sympy
cisco
bellman-ford
hystrix
corona
supervisord
twisted
synthesis
vertica
hidden
rpmbuild
codefluent
adobe-illustrator
cmake-gui
unity-container
web-analytics
kamailio
generator
quantitative-finance
software-packaging
ratio
password-generator
window-managers
unrar
spreadsheetgear
clipboard
sap-lumira
android-service
tf-idf
jsonresult
phpstorm-2016.1
infopath2010
publishing
actframework
db2-luw
nppexec
cups
newtons-method
fiware-wirecloud
google-prediction
elasticsearch-aggregation
notesview
docker-ucp
cloudwatch
ssi
supertest
popen
test-data
mechanicalturk
dymola
e
decoder
jenkins-workflow
sharepoint-apps
android-async-http
gridbaglayout
wif4.5
outlook.com
boost-proto
linuxbrew
knife
mobilefirst-server
algebraixlib
erlog
vs-unit-testing-framework
xml-signature
nidaqmx
loginview
code-complexity
.htpasswd
webaii
hotswap
property-injection
pbkdf2
apache-shindig
django-facebook
coalesce
node.js-stream
oembed
smartfox
wndproc
hardcode
background-repeat
expression-web
filelock
azure-acs
jquery-1.4
dip
pinax
sqlsitemapprovider
index.dat
datagridcolumn

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App