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

How to define a function with two enum parameters where the 2nd type is determined by the 1st?
How do I slice an array with an i32 limit?
Path of references on a tree structure
Type annotation in a pattern match in Rust?
rust: cannot move out of indexed context [duplicate]
Ambiguity of type during initialization
Cannot move out of borrowed content [E0507]
Is there a way to simplify converting an Option into a Result without a macro?
Does Rust binary_search have a bug?
What is imported when I use a struct from another module?
Recognize floating point from input with nom
Referencing while a mut reference exists in scope
Why does cloning my custom type result in &T instead of T?
Iterate over byte vector and save pointers to strings
How do I disable an entire example based on features?
Chunking a vector of strings

Categories

HOME
libgdx
azure-functions
freeradius
yii
dotnetnuke
ews
biztalk
jersey-2.0
twitter-fabric
firebase-database
phpseclib
timber
tup
siesta
heuristics
createjs
amazon-elb
jpa-2.0
texas-instruments
nest-api
cpu-usage
bazaar
fido-u2f
mime-types
exchange-server-2010
backendless
firemonkey-style
unrar
onchange
boolean-logic
jsonresult
guice
objectmapper
busboy
iscroll
stat
windows-store
pyttsx
xcode8.2
scala-breeze
google-news
palindrome
mobile-angular-ui
mechanicalturk
ltrace
portal
scheduledexecutorservice
pyaudio
p6spy
carmen
preferenceactivity
currency-exchange-rates
wepay
teensy
lovefield
ibm-was
chicagoboss
knife
fantom
deque
createfile
hp-idol-ondemand
inequality
quantify
lmax
communicate
sqlbindparameter
flipboard
autonumber
sensormanager
infinite
mongo-jackson-mapper
red-system
uitextfielddelegate
fitch-proofs
boost-foreach
motodev-studio
startupscript
servlet-container
channelfactory
tabbarcontroller
raw-data
.net-services
data-retrieval
downcasting
efs

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App