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

Nested method calls with &mut receivers result in borrow checker errors
How do I perform an operation only when two variables are not None without copying them?
How to avoid mutex borrowing problems when using it's guard
How do I solve the “missing associated type `Err` value” error?
How to match against a &'static str in Rust
In Rust, what's the difference between “{}” and “{:?}” inside a println!? [duplicate]
how to use stdout save image in Rust?
What is the safe way to convert a Vec<T> to a &[T]
How do I shuffle a VecDeque?
Can I use a mutable reference method like a value-passing one?
How to execute Rust code directly on Unix systems? (using the shebang)
Convenient 'Option<Box<Any>>' access when success is assured?
Use a closure inside a thread
How to change the variable from inside Fn closure in Rust?
Create mutual reference for rust [duplicate]
How do I safely use an object while it is mutably borrowed?

Categories

HOME
oracle
typelite
clearcase
redmine
operating-system
subdomain
cryptography
tibco
scheduler
wine
solution
clish
google-awareness
closures
exec-maven-plugin
adobe-illustrator
clr
jest
neo4j.rb
gollum-wiki
stackexchange.redis
sap-lumira
jackrabbit-oak
code-climate
bobo-browse.net
substance
dotcms
series
listjs
kendo-listview
rails-postgresql
cups
mv
android-n
best-buy-api
right-click
grails-spring-security
opal-framework
word-cloud
notesview
httphandler
apache-toree
bit-shift
realstudio
icecast
password-hash
sharpdx
datediff
dtd
glassfish-4.1
degrees
oid
ternary-operator
decoder
livecycle
p6spy
qpixmap
uibinder
frame-grab
sharepoint-apps
distributed-cache
gwt-syncproxy
okta-api
pack
miniconda
nette
bootstrap-wysiwyg
nsmutabledata
incron
createfile
device-admin
object-code
flipboard
roxy-fileman
mod-perl
profiles
codahale-metrics
coalesce
ax
indesign-server
dynamic-rdlc-generation
axacropdf
multiscaleimage
daap
zend-pdf
gwt-celltable
infopath-2007
asp.net-mvc-views
jmenu
aptitude
html-components
ntruencrypt
efs
acceleration

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