src/collection.rs

branch
dev
changeset 124
6aa955ad8122
parent 59
9226980e45a7
equal deleted inserted replaced
122:495448cca603 124:6aa955ad8122
3 */ 3 */
4 4
5 use crate::loc::Loc; 5 use crate::loc::Loc;
6 6
7 /// An abstract collection of elements. 7 /// An abstract collection of elements.
8 pub trait Collection : IntoIterator<Item = Self::Element> { 8 pub trait Collection: IntoIterator<Item = Self::Element> {
9 /// Type of elements of the collection 9 /// Type of elements of the collection
10 type Element; 10 type Element;
11 /// Iterator over references to elements of the collection 11 /// Iterator over references to elements of the collection
12 type RefsIter<'a> : Iterator<Item=&'a Self::Element> where Self : 'a; 12 type RefsIter<'a>: Iterator<Item = &'a Self::Element>
13 where
14 Self: 'a;
13 15
14 /// Returns an iterator over references to elements of the collection. 16 /// Returns an iterator over references to elements of the collection.
15 fn iter_refs(&self) -> Self::RefsIter<'_>; 17 fn iter_refs(&self) -> Self::RefsIter<'_>;
16 } 18 }
17 19
18 /// An abstract collection of mutable elements. 20 /// An abstract collection of mutable elements.
19 pub trait CollectionMut : Collection { 21 pub trait CollectionMut: Collection {
20 /// Iterator over references to elements of the collection 22 /// Iterator over references to elements of the collection
21 type RefsIterMut<'a> : Iterator<Item=&'a mut Self::Element> where Self : 'a; 23 type RefsIterMut<'a>: Iterator<Item = &'a mut Self::Element>
24 where
25 Self: 'a;
22 26
23 /// Returns an iterator over references to elements of the collection. 27 /// Returns an iterator over references to elements of the collection.
24 fn iter_refs_mut(&mut self) -> Self::RefsIterMut<'_>; 28 fn iter_refs_mut(&mut self) -> Self::RefsIterMut<'_>;
25 } 29 }
26 30
49 } 53 }
50 } 54 }
51 55
52 slice_like_collection!(Vec<E> where E); 56 slice_like_collection!(Vec<E> where E);
53 slice_like_collection!([E; N] where E, const N : usize); 57 slice_like_collection!([E; N] where E, const N : usize);
54 slice_like_collection!(Loc<E, N> where E, const N : usize); 58 slice_like_collection!(Loc<N, E> where E, const N : usize);

mercurial