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 value from match to Err(e)
Get actual path symlink is pointing to
How do I create a class with multiple instantiation options
Struct must outlive member reference
How to solve this lifetime-related error?
How to pass a mutable function parameter as argument to another function?
How to compile and run an optimized Rust program with overflow checking enabled
How do I specialize a trait function?
How to store recursive ref inside of a struct
Value does not live long enough with explicit lifetime, but does live long enough when omitted
Borrowing Option::and_then
Redirect panics to a specified buffer
How can I have a container where the items have access to the container?
Borrow inner data from struct in a wrapper function
Allowing both static variables and boxes as a function argument?
Assigning values in a 2D array

Categories

HOME
hpoo
entity-framework
lambda
adfs3.0
paypal-ipn
stacktrace.js
google-webmaster-tools
google-sheets-query
mosquitto
responsive-design
msmq
gtk
migrate
vimeo
twisted
varnish-vcl
salt-cloud
altium-designer
mime-types
acl
high-availability
window-managers
adapter
mdns
social-networking
copy-protection
tightvnc
reporting
devtools
directfb
spring-rabbitmq
java-stream
polyml
redgate
eclipse-gmf
strapi
django-smart-selects
linq.js
praat
oauth2
grails3.2.0
classnotfoundexception
moinmoin
code-push
kitura
flume-twitter
absolute
qvtkwidget
knockout-2.0
non-linear-regression
nivo-slider
deedle
glimpse
msxml
jpda
static-methods
yii2-model
verisign
jsr363
webgrind
linuxbrew
smart-tv
http.client
highest
cache-manifest
algebraixlib
tabris
communicate
jomsocial
code39
ember-table
arel
jbox2d
donut-chart
tfs-sdk
reentrancy
xalan
java.lang.class
firebird1.5
differentiation
servlet-container
.net-services
rtti
html-generation

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile