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

Right way to share a reference between closures
Borrow checker and function arguments in Rust, correct or over zealous?
Most idiomatic way to create a default struct
How to return an Iterator from a Map [duplicate]
Do all primitive types implement the Copy trait?
Comparison of two floats in Rust to arbitrary level of precision
Is there a convenient way to represent x86 instructions in a struct or other language feature?
Why isn't `regex!` a wrapper for `Regex::new` to offer the same regex matching speed?
Lifetime annotation for closure argument
“overflow while adding drop-check rules” while implementing a fingertree
Is it possible to coerce slices/vectors into 'Cow<[type]>' in function arguments?
Unable to get started with diesel.rs and Rust 1.16 nightly
Do all generic types implement the Copy trait?
How to add code only for specific Rust version without using a build script?
Match expects &Result when I want to use Result
Parsing a char to u32

Categories

HOME
opengl
nam
protocol-buffers
verification
kendo-dropdown
selenium-builder
subdomain
command-prompt
websocket
autocomplete
tabs
swift2
material-components
linker
ui-automation
mithril.js
cdi
tfs2010
mailing-list
stack-overflow
twitter-oauth
powermock
dma
quartz.net
function-points
react-dnd
web-push
npoi
iwebbrowser2
pyspark-sql
django-import-export
sfml
ninject
dnsmasq
intune
commonsware-cwac
fotorama
gsp
listjs
android-canvas
polyml
ms-solver-foundation
djcelery
tidal-scheduler
best-buy-api
jacoco-maven-plugin
icepdf
asihttprequest
bit-shift
intellij-lombok-plugin
iptv
android-webservice
ltrace
rational-performance-test
openseadragon
dojo-build
eclemma
cryptojs
bayesglm
linuxbrew
nastran
highest
calcite
auto-generate
darwin
bootstrap-wysiwyg
textscan
nsmutabledata
tkx
kognitio-wx2
sql-processor
n-tier-architecture
password-recovery
multivariate-testing
tabris
category-theory
sql-function
wso2bam
jmenubar
mousemotionlistener
quickgraph
jquery-lazyload
ntlmv2
cyrillic
red-system
getopt-long
cakeyframeanimation
java.lang.class
opends
fitch-proofs
affinetransform
will-paginate
odac
iphone-sdk-4.3
facebook-fbml
rootkit
account-management

Resources

Encrypt Message