Failed to enter custom generic alias

Given the following:

use std::fmt::Debug; #[derive(Debug)] enum A<T: Debug> { X, Y(T), } #[derive(Debug)] struct B; type C = A<B>; // use A<B> as C; // Does not compile 

I can use it like:

 fn main() { let val0 = A::X::<B>; let val1 = A::Y::<B>(B); println!("{:?}\t{:?}", val0, val1); } 

But then for more than one common parameter (or if A , B , etc. were much longer than the names, and then for an alias, I tried the following, but it does not compile:

 fn main() { let val0 = C::X; let val1 = C::Y(B); println!("{:?}\t{:?}", val0, val1); } 

with mistakes:

 src/main.rs:656:16: 656:20 error: no associated item named `X` found for type `A<B>` in the current scope src/main.rs:656 let val0 = C::X; ^~~~ src/main.rs:657:16: 657:20 error: no associated item named `Y` found for type `A<B>` in the current scope src/main.rs:657 let val1 = C::Y(B); 

As also noted, I cannot use use to solve the problem. Is there any way around this (because typing it all seems cumbersome)?

 rustc --version rustc 1.9.0 (e4e8b6668 2016-05-18) 
+6
source share
1 answer

Is there a way around it (because printing all this seems cumbersome)?

You can specify C as a variable type so that you can use A::X or A::Y without explicitly specifying a type parameter:

 let val0: C = A::X; let val1: C = A::Y(B); 
+4
source

All Articles