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 write an integer as a string to a byte array with no_std?
How to get struct fields and fields type in compiler plugin?
How is my reference to a struct member still valid after the struct was moved?
What is the difference between casting to `i32` from `usize` versus the other way?
Usability of infinite loop in Rust
How to move boxing into a function instead of caller side
How to return a vector of boxed traits using map (functional rather than imperative)
Why do I get a `trait bound `[T]: std::marker::Sized` is not satisfied when I try and implement Ord and Eq manually on unsized types?
Rust statement reordering when prompting for input on stdin [duplicate]
what does the first explicit lifetime specifier on an impl mean?
Implementing a trait for closures results in bound/concrete lifetime mismatch
Is Rust using region-based memory management?
After a load test, every new mio connection immediately hangs up
Importing non-root module from multiple non-root binaries
Could this scoped thread code be changed to use `FnOnce()` instead of `Box<FnOnce()>`?
Unable to create hyper::Client because the compiler cannot infer enough type information

Categories

HOME
bots
dronekit-python
liferay-7
navigation
azure-mobile-services
clone
position
timber
anchor
gtk
fbloginview
angular4
squirrel-sql
nest-api
rpmbuild
robolectric
scheduled-tasks
multiple-tables
pe
data-type-conversion
sqlplus
backtracking
acl
rxjs5
intel
sybase-ase
backendless
tortoisemerge
password-generator
strophe.js
math.js
annotation-processing
npoi
adapter
sparkle
xenapp
toad
publishing
john-the-ripper
caesar-cipher
serversocket
amazon-kms
dreamfactory
nppexec
bluemixtools
xvfb
strapi
cheat-engine
classnotfoundexception
vb.net-to-c#
flipkart
access-denied
fluid-mac-app-engine
type-inference
react-intl
rm
icecast
supertest
line-intersection
gtk#
wikimapia
apache-modules
rational-performance-test
pjax
nsrunloop
wolfram-language
node-glob
distributed-cache
gridbaglayout
jsr363
ajax4jsf
grinder
deeplink
embeddedwebserver
quercus
shell-extensions
string.format
adhoc-polymorphism
webmethod
otl
neo4jphp
miglayout
bittorrent-sync
property-injection
nosql-aggregation
mod-perl
compiler-flags
bcdedit
gprof
chronometer
websphere-6.1
system-information
dropshadow
motodev-studio
botnet
nsrangeexception
qcar-sdk
libxslt
zend-test
firephp
3270
rakudo

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