File tree Expand file tree Collapse file tree 2 files changed +13
-13
lines changed Expand file tree Collapse file tree 2 files changed +13
-13
lines changed Original file line number Diff line number Diff line change 1- struct Tup ( f64 , ) ;
2- struct GenTup < T > ( T , ) ;
1+ struct Val ( f64 , ) ;
2+ struct GenVal < T > ( T , ) ;
33
4- // impl of Tup
5- impl Tup {
4+ // impl of Val
5+ impl Val {
66 fn value ( & self ) -> & f64 { & self . 0 }
77}
88
9- // impl of GenTup for a generic type `T`
10- impl < T > GenTup < T > {
9+ // impl of GenVal for a generic type `T`
10+ impl < T > GenVal < T > {
1111 fn value ( & self ) -> & T { & self . 0 }
1212}
1313
1414fn main ( ) {
15- let x = Tup ( 3.0 ) ;
16- let y = GenTup ( 3i32 ) ;
15+ let x = Val ( 3.0 ) ;
16+ let y = GenVal ( 3i32 ) ;
1717
1818 println ! ( "{}, {}" , x. value( ) , y. value( ) ) ;
1919}
Original file line number Diff line number Diff line change @@ -2,14 +2,14 @@ Similar to functions, implementations require care to remain generic.
22
33``` rust
44struct S ; // A null struct
5- struct GenericTup <T >(T ,);
5+ struct GenericVal <T >(T ,);
66
7- // impl of GenericTup we specifically specialize:
8- impl GenericTup <f32 > {} // Specialize to `f32`
9- impl GenericTup <S > {} // Specialize to `S` defined above
7+ // impl of GenericVal we specifically specialize:
8+ impl GenericVal <f32 > {} // Specialize to `f32`
9+ impl GenericVal <S > {} // Specialize to `S` defined above
1010
1111// `<T>` Must precede the type to remain generic
12- impl <T > GenericTup <T > {}
12+ impl <T > GenericVal <T > {}
1313```
1414
1515Note: Rust does not * currently* allow overlap between implementations. The
You can’t perform that action at this time.
0 commit comments