19
19
// associated-type-constructors-part-2-family-traits/
20
20
21
21
trait Collection < T > {
22
- fn empty ( ) -> Self ;
23
- fn add ( & mut self , value : T ) ;
24
- fn iterate < ' iter > ( & ' iter self ) -> Self :: Iter < ' iter > ;
25
- //~^ ERROR lifetime parameters are not allowed on this type [E0110]
26
22
type Iter < ' iter > : Iterator < Item =& ' iter T > ;
27
23
type Family : CollectionFamily ;
28
24
// Test associated type defaults with parameters
29
25
type Sibling < U > : Collection < U > = <<Self as Collection < T > >:: Family as CollectionFamily >::
30
26
Member < U > ;
31
27
//~^ ERROR type parameters are not allowed on this type [E0109]
28
+
29
+ fn empty ( ) -> Self ;
30
+
31
+ fn add ( & mut self , value : T ) ;
32
+
33
+ fn iterate < ' iter > ( & ' iter self ) -> Self :: Iter < ' iter > ;
34
+ //~^ ERROR lifetime parameters are not allowed on this type [E0110]
32
35
}
33
36
34
37
trait CollectionFamily {
@@ -42,23 +45,28 @@ impl CollectionFamily for VecFamily {
42
45
}
43
46
44
47
impl < T > Collection < T > for Vec < T > {
48
+ type Iter < ' iter > = std:: slice:: Iter < ' iter , T > ;
49
+ type Family = VecFamily ;
50
+
45
51
fn empty ( ) -> Self {
46
52
Vec :: new ( )
47
53
}
54
+
48
55
fn add ( & mut self , value : T ) {
49
56
self . push ( value)
50
57
}
58
+
51
59
fn iterate < ' iter > ( & ' iter self ) -> Self :: Iter < ' iter > {
52
60
//~^ ERROR lifetime parameters are not allowed on this type [E0110]
53
61
self . iter ( )
54
62
}
55
- type Iter < ' iter > = std:: slice:: Iter < ' iter , T > ;
56
- type Family = VecFamily ;
57
63
}
58
64
59
65
fn floatify < C > ( ints : & C ) -> <<C as Collection < i32 > >:: Family as CollectionFamily >:: Member < f32 >
60
66
//~^ ERROR type parameters are not allowed on this type [E0109]
61
- where C : Collection < i32 > {
67
+ where
68
+ C : Collection < i32 > ,
69
+ {
62
70
let mut res = C :: Family :: Member :: < f32 > :: empty ( ) ;
63
71
for & v in ints. iterate ( ) {
64
72
res. add ( v as f32 ) ;
@@ -68,7 +76,9 @@ fn floatify<C>(ints: &C) -> <<C as Collection<i32>>::Family as CollectionFamily>
68
76
69
77
fn floatify_sibling < C > ( ints : & C ) -> <C as Collection < i32 > >:: Sibling < f32 >
70
78
//~^ ERROR type parameters are not allowed on this type [E0109]
71
- where C : Collection < i32 > {
79
+ where
80
+ C : Collection < i32 > ,
81
+ {
72
82
let mut res = C :: Family :: Member :: < f32 > :: empty ( ) ;
73
83
for & v in ints. iterate ( ) {
74
84
res. add ( v as f32 ) ;
0 commit comments