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 using Rust do I assign the value being matched as the result?
How Do I pass object “std::rand::task_rng()” to a function in Rust?
Using Rust, is there a faster/shorter way to initialize variables in a struct?
How does Rust handle rounding in conversion of f64 to i64?
Using Rust and the match statement how can I assign a TcpListener?
How can I detect an error rather than have this Rust program abort?
Why does i32 perform better than i64 using Rust on Win8-64?
Error with Rust: cannot call a method whose type contains a self-type through an object
Comparing string with static string
How do a pass a database variable to a function in Rust?
What happens in Rust using “match” if nothing matches?
The English alphabet as a vector of characters in Rust
How do I convert a Vector of bytes (u8) to a string
Why using Rust does passing a mutable struct to a function result in immutable fields?
Using managed and owned pointers together
How can I read and write a text file in Rust? [duplicate]

Categories

HOME
ionic2
user-interface
powerbi
redmine
postgresql-9.4
enums
portable-class-library
moodle-api
bittorrent
facebook-android-sdk
yahoo
fbloginview
buffer
amazon-elb
django-rq
tomcat8
salt-cloud
android-permissions
web-analytics
bosun
sharedpreferences
generator
restier
history.js
tortoisehg
ccavenue
django-import-export
ninject
social-networking
substance
copy-protection
adminer
bean-validation
spinner
django-crispy-forms
unification
llvm-ir
rdp
utf
grails-spring-security
newtons-method
ejml
viewcontroller
dagger
google-prediction
dbcc
web-inspector
type-inference
doctrine-extensions
autorelease
android-5.0-lollipop
spring.net
embedded-v8
webvtt
apache-modules
swiperefreshlayout
openerp-6
prefetch
bigdecimal
xcode6.4
bilinear-interpolation
decoder
nunit-console
verisign
ajax4jsf
algebraixlib
web-api
sablecc
nsmutabledata
juttle
rpg
hotswap
accountmanager
spring-security-acl
django-facebook
icenium
smartfox
story
telerik-ajax
thejit
background-repeat
differentiation
servercontrol
startupscript
kext
printqueue
gaelyk
odac
ixmldomdocument
.net-client-profile
service-factory

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