File tree Expand file tree Collapse file tree 1 file changed +13
-9
lines changed Expand file tree Collapse file tree 1 file changed +13
-9
lines changed Original file line number Diff line number Diff line change @@ -4,39 +4,43 @@ Similar to functions, implementations require care to remain generic.
44
55``` rust
66struct S ; // Concrete type `S`
7- struct GenericVal <T >(T , ); // Generic type `GenericVal`
7+ struct GenericVal <T >(T ); // Generic type `GenericVal`
88
99// impl of GenericVal where we explicitly specify type parameters:
1010impl GenericVal <f32 > {} // Specify `f32`
1111impl GenericVal <S > {} // Specify `S` as defined above
1212
1313// `<T>` Must precede the type to remain generic
14- impl <T > GenericVal <T > {}
14+ impl <T > GenericVal <T > {}
1515```
1616
1717``` rust,editable
1818struct Val {
19- val: f64
19+ val: f64,
2020}
2121
22- struct GenVal<T>{
23- gen_val: T
22+ struct GenVal<T> {
23+ gen_val: T,
2424}
2525
2626// impl of Val
2727impl Val {
28- fn value(&self) -> &f64 { &self.val }
28+ fn value(&self) -> &f64 {
29+ &self.val
30+ }
2931}
3032
3133// impl of GenVal for a generic type `T`
32- impl <T> GenVal<T> {
33- fn value(&self) -> &T { &self.gen_val }
34+ impl<T> GenVal<T> {
35+ fn value(&self) -> &T {
36+ &self.gen_val
37+ }
3438}
3539
3640fn main() {
3741 let x = Val { val: 3.0 };
3842 let y = GenVal { gen_val: 3i32 };
39-
43+
4044 println!("{}, {}", x.value(), y.value());
4145}
4246```
You can’t perform that action at this time.
0 commit comments