traitsequence/implementation/
vec.rs

1use crate::interface::{CloneableSequence, EditableSequence, OwnedSequence, Sequence, SequenceMut};
2
3impl<Item> Sequence<Item, [Item]> for Vec<Item> {
4    type Iterator<'a>
5        = std::slice::Iter<'a, Item>
6    where
7        Item: 'a;
8    fn iter(&self) -> Self::Iterator<'_> {
9        self[..].iter()
10    }
11
12    fn len(&self) -> usize {
13        Vec::len(self)
14    }
15}
16
17impl<Item> SequenceMut<Item, [Item]> for Vec<Item> {
18    type IteratorMut<'a>
19        = std::slice::IterMut<'a, Item>
20    where
21        Item: 'a;
22
23    fn iter_mut(&mut self) -> Self::IteratorMut<'_> {
24        self[..].iter_mut()
25    }
26}
27
28impl<Item> OwnedSequence<Item, [Item]> for Vec<Item> {}
29
30impl<Item: Clone> CloneableSequence<Item, [Item]> for Vec<Item> {}
31
32impl<Item> EditableSequence<Item, [Item]> for Vec<Item> {
33    fn set(&mut self, index: usize, item: Item) {
34        self[index] = item;
35    }
36
37    fn split_off(&mut self, at: usize) -> Self {
38        Vec::split_off(self, at)
39    }
40
41    fn reserve(&mut self, additional: usize) {
42        self.reserve(additional);
43    }
44
45    fn resize(&mut self, new_len: usize, value: Item)
46    where
47        Item: Clone,
48    {
49        self.resize(new_len, value);
50    }
51
52    fn resize_with(&mut self, new_len: usize, generator: impl FnMut() -> Item) {
53        self.resize_with(new_len, generator);
54    }
55
56    fn push(&mut self, item: Item) {
57        self.push(item)
58    }
59
60    fn splice(
61        &mut self,
62        range: std::ops::Range<usize>,
63        replace_with: impl IntoIterator<Item = Item>,
64    ) {
65        self.splice(range, replace_with);
66    }
67}