Debian Codegraph @

src/lib.rs

raw symbols SCIP
1 //! This crate provides a pin-safe, append-only vector which guarantees never
2 //! to move the storage for an element once it has been allocated.
3
4 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{
5 opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/::{Indexrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#, IndexMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#},
6 slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/,
7 };
8
9 struct Chunkrust-analyzer cargo chunky-vec 0.1.0 Chunk#<T> {
10 /// The elements of this chunk.
11 elementsrust-analyzer cargo chunky-vec 0.1.0 Chunk#elements.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<T>,
12 }
13
14 impl<T> Chunkrust-analyzer cargo chunky-vec 0.1.0 Chunk#<T> {
15 fn with_capacityrust-analyzer cargo chunky-vec 0.1.0 impl#[`Chunk<T>`]with_capacity().(capacity: usize) -> Selfrust-analyzer cargo chunky-vec 0.1.0 impl#[`Chunk<T>`] {
16 let elements = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]with_capacity().(capacity);
17 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(elements.capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]capacity().(), capacity);
18 Selfrust-analyzer cargo chunky-vec 0.1.0 impl#[`Chunk<T>`] { elementsrust-analyzer cargo chunky-vec 0.1.0 Chunk#elements. }
19 }
20
21 fn lenrust-analyzer cargo chunky-vec 0.1.0 impl#[`Chunk<T>`]len().(&self) -> usize {
22 self.elementsrust-analyzer cargo chunky-vec 0.1.0 Chunk#elements..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().()
23 }
24
25 /// Returns the number of available empty elements.
26 fn availablerust-analyzer cargo chunky-vec 0.1.0 impl#[`Chunk<T>`]available().(&self) -> usize {
27 self.elementsrust-analyzer cargo chunky-vec 0.1.0 Chunk#elements..capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]capacity().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().self.elementsrust-analyzer cargo chunky-vec 0.1.0 Chunk#elements..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().()
28 }
29
30 /// Returns a shared reference to the element at the given index.
31 ///
32 /// # Panics
33 ///
34 /// Panics if the index is out of bounds.
35 pub fn getrust-analyzer cargo chunky-vec 0.1.0 impl#[`Chunk<T>`]get().(&self, index: usize) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&T> {
36 self.elementsrust-analyzer cargo chunky-vec 0.1.0 Chunk#elements..getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get().(index)
37 }
38
39 /// Returns an exclusive reference to the element at the given index.
40 ///
41 /// # Panics
42 ///
43 /// Panics if the index is out of bounds.
44 pub fn get_mutrust-analyzer cargo chunky-vec 0.1.0 impl#[`Chunk<T>`]get_mut().(&mut self, index: usize) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&mut T> {
45 self.elementsrust-analyzer cargo chunky-vec 0.1.0 Chunk#elements..get_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get_mut().(index)
46 }
47
48 /// Pushes a new value into the fixed capacity entry.
49 ///
50 /// # Panics
51 ///
52 /// If the entry is already at its capacity.
53 /// Note that this panic should never happen since the entry is only ever
54 /// accessed by its outer chunk vector that checks before pushing.
55 pub fn pushrust-analyzer cargo chunky-vec 0.1.0 impl#[`Chunk<T>`]push().(&mut self, new_value: T) {
56 if self.availablerust-analyzer cargo chunky-vec 0.1.0 impl#[`Chunk<T>`]available().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().0 {
57 panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("No available elements.")
58 }
59 self.elementsrust-analyzer cargo chunky-vec 0.1.0 Chunk#elements..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(new_value);
60 }
61
62 pub fn push_getrust-analyzer cargo chunky-vec 0.1.0 impl#[`Chunk<T>`]push_get().(&mut self, new_value: T) -> &mut T {
63 self.pushrust-analyzer cargo chunky-vec 0.1.0 impl#[`Chunk<T>`]push().(new_value);
64 unsafe {
65 let last = self.elementsrust-analyzer cargo chunky-vec 0.1.0 Chunk#elements..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().1;
66 self.elementsrust-analyzer cargo chunky-vec 0.1.0 Chunk#elements..get_unchecked_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get_unchecked_mut().(last)
67 }
68 }
69
70 /// Returns an iterator over the elements of the chunk.
71 pub fn iterrust-analyzer cargo chunky-vec 0.1.0 impl#[`Chunk<T>`]iter().(&self) -> slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/::Iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/Iter#<T> {
72 self.elementsrust-analyzer cargo chunky-vec 0.1.0 Chunk#elements..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()
73 }
74
75 /// Returns an iterator over the elements of the chunk.
76 pub fn iter_mutrust-analyzer cargo chunky-vec 0.1.0 impl#[`Chunk<T>`]iter_mut().(&mut self) -> slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/::IterMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/IterMut#<T> {
77 self.elementsrust-analyzer cargo chunky-vec 0.1.0 Chunk#elements..iter_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter_mut().()
78 }
79 }
80
81 impl<T> Indexrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#<usize> for Chunkrust-analyzer cargo chunky-vec 0.1.0 Chunk#<T> {
82 type Outputrust-analyzer cargo chunky-vec 0.1.0 impl#[`Chunk<T>`][`Index<usize>`]Output# = T;
83
84 fn indexrust-analyzer cargo chunky-vec 0.1.0 impl#[`Chunk<T>`][`Index<usize>`]index().(&self, index: usize) -> &Selfrust-analyzer cargo chunky-vec 0.1.0 impl#[`Chunk<T>`][`Index<usize>`]::Outputrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#Output# {
85 self.getrust-analyzer cargo chunky-vec 0.1.0 impl#[`Chunk<T>`]get().(index).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("index out of bounds")
86 }
87 }
88
89 impl<T> IndexMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#<usize> for Chunkrust-analyzer cargo chunky-vec 0.1.0 Chunk#<T> {
90 fn index_mutrust-analyzer cargo chunky-vec 0.1.0 impl#[`Chunk<T>`][`IndexMut<usize>`]index_mut().(&mut self, index: usize) -> &mut Selfrust-analyzer cargo chunky-vec 0.1.0 impl#[`Chunk<T>`][`IndexMut<usize>`]::Outputrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#Output# {
91 self.get_mutrust-analyzer cargo chunky-vec 0.1.0 impl#[`Chunk<T>`]get_mut().(index).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("index out of bounds")
92 }
93 }
94
95 /// Pin safe vector
96 ///
97 /// An append only vector that never moves the backing store for each element.
98 pub struct ChunkyVecrust-analyzer cargo chunky-vec 0.1.0 ChunkyVec#<T> {
99 /// The chunks holding elements
100 chunksrust-analyzer cargo chunky-vec 0.1.0 ChunkyVec#chunks.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Chunkrust-analyzer cargo chunky-vec 0.1.0 Chunk#<T>>,
101 }
102
103 impl<T> Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default# for ChunkyVecrust-analyzer cargo chunky-vec 0.1.0 ChunkyVec#<T> {
104 fn defaultrust-analyzer cargo chunky-vec 0.1.0 impl#[`ChunkyVec<T>`][Default]default().() -> Selfrust-analyzer cargo chunky-vec 0.1.0 impl#[`ChunkyVec<T>`][Default] {
105 Selfrust-analyzer cargo chunky-vec 0.1.0 impl#[`ChunkyVec<T>`][Default] {
106 chunksrust-analyzer cargo chunky-vec 0.1.0 ChunkyVec#chunks.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::defaultrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`][Default]default().(),
107 }
108 }
109 }
110
111 impl<T> Unpinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Unpin# for ChunkyVecrust-analyzer cargo chunky-vec 0.1.0 ChunkyVec#<T> {}
112
113 impl<T> ChunkyVecrust-analyzer cargo chunky-vec 0.1.0 ChunkyVec#<T> {
114 const DEFAULT_CAPACITYrust-analyzer cargo chunky-vec 0.1.0 impl#[`ChunkyVec<T>`]DEFAULT_CAPACITY.: usize = 32;
115
116 pub fn lenrust-analyzer cargo chunky-vec 0.1.0 impl#[`ChunkyVec<T>`]len().(&self) -> usize {
117 if self.chunksrust-analyzer cargo chunky-vec 0.1.0 ChunkyVec#chunks..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() {
118 0
119 } else {
120 // # Safety - There is at least one chunk here.
121 (self.chunksrust-analyzer cargo chunky-vec 0.1.0 ChunkyVec#chunks..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().1) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().Selfrust-analyzer cargo chunky-vec 0.1.0 impl#[`ChunkyVec<T>`]::DEFAULT_CAPACITYrust-analyzer cargo chunky-vec 0.1.0 impl#[`ChunkyVec<T>`]DEFAULT_CAPACITY. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().self.chunksrust-analyzer cargo chunky-vec 0.1.0 ChunkyVec#chunks..lastrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]last().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().lenrust-analyzer cargo chunky-vec 0.1.0 impl#[`Chunk<T>`]len().()
122 }
123 }
124
125 pub fn is_emptyrust-analyzer cargo chunky-vec 0.1.0 impl#[`ChunkyVec<T>`]is_empty().(&self) -> bool {
126 // # Safety - Since it's impossible to pop, at least one chunk means we're not empty.
127 self.chunksrust-analyzer cargo chunky-vec 0.1.0 ChunkyVec#chunks..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().()
128 }
129
130 /// Returns an iterator that yields shared references to the elements of the bucket vector.
131 pub fn iterrust-analyzer cargo chunky-vec 0.1.0 impl#[`ChunkyVec<T>`]iter().(&self) -> Iterrust-analyzer cargo chunky-vec 0.1.0 Iter#<T> {
132 Iterrust-analyzer cargo chunky-vec 0.1.0 Iter#::newrust-analyzer cargo chunky-vec 0.1.0 impl#[`Iter<'a, T>`]new().(self)
133 }
134
135 /// Returns an iterator that yields exclusive reference to the elements of the bucket vector.
136 pub fn iter_mutrust-analyzer cargo chunky-vec 0.1.0 impl#[`ChunkyVec<T>`]iter_mut().(&mut self) -> IterMutrust-analyzer cargo chunky-vec 0.1.0 IterMut#<T> {
137 IterMutrust-analyzer cargo chunky-vec 0.1.0 IterMut#::newrust-analyzer cargo chunky-vec 0.1.0 impl#[`IterMut<'a, T>`]new().(self)
138 }
139
140 /// Returns a shared reference to the element at the given index if any.
141 pub fn getrust-analyzer cargo chunky-vec 0.1.0 impl#[`ChunkyVec<T>`]get().(&self, index: usize) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&T> {
142 let (x, y) = (
143 index rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div().Selfrust-analyzer cargo chunky-vec 0.1.0 impl#[`ChunkyVec<T>`]::DEFAULT_CAPACITYrust-analyzer cargo chunky-vec 0.1.0 impl#[`ChunkyVec<T>`]DEFAULT_CAPACITY.,
144 index rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem().%rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem().Selfrust-analyzer cargo chunky-vec 0.1.0 impl#[`ChunkyVec<T>`]::DEFAULT_CAPACITYrust-analyzer cargo chunky-vec 0.1.0 impl#[`ChunkyVec<T>`]DEFAULT_CAPACITY.,
145 );
146 self.chunksrust-analyzer cargo chunky-vec 0.1.0 ChunkyVec#chunks..getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get().(x).and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|chunk| chunk.getrust-analyzer cargo chunky-vec 0.1.0 impl#[`Chunk<T>`]get().(y))
147 }
148
149 /// Returns an exclusive reference to the element at the given index if any.
150 pub fn get_mutrust-analyzer cargo chunky-vec 0.1.0 impl#[`ChunkyVec<T>`]get_mut().(&mut self, index: usize) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&mut T> {
151 let (x, y) = (
152 index rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div().Selfrust-analyzer cargo chunky-vec 0.1.0 impl#[`ChunkyVec<T>`]::DEFAULT_CAPACITYrust-analyzer cargo chunky-vec 0.1.0 impl#[`ChunkyVec<T>`]DEFAULT_CAPACITY.,
153 index rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem().%rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem().Selfrust-analyzer cargo chunky-vec 0.1.0 impl#[`ChunkyVec<T>`]::DEFAULT_CAPACITYrust-analyzer cargo chunky-vec 0.1.0 impl#[`ChunkyVec<T>`]DEFAULT_CAPACITY.,
154 );
155 self.chunksrust-analyzer cargo chunky-vec 0.1.0 ChunkyVec#chunks..get_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get_mut().(x).and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|chunk| chunk.get_mutrust-analyzer cargo chunky-vec 0.1.0 impl#[`Chunk<T>`]get_mut().(y))
156 }
157
158 /// Pushes a new element onto the bucket vector.
159 ///
160 /// # Note
161 ///
162 /// This operation will never move other elements, reallocates or otherwise
163 /// invalidate pointers of elements contained by the bucket vector.
164 pub fn pushrust-analyzer cargo chunky-vec 0.1.0 impl#[`ChunkyVec<T>`]push().(&mut self, new_value: T) {
165 self.push_getrust-analyzer cargo chunky-vec 0.1.0 impl#[`ChunkyVec<T>`]push_get().(new_value);
166 }
167
168 pub fn push_getrust-analyzer cargo chunky-vec 0.1.0 impl#[`ChunkyVec<T>`]push_get().(&mut self, new_value: T) -> &mut T {
169 if self.chunksrust-analyzer cargo chunky-vec 0.1.0 ChunkyVec#chunks..lastrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]last().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(Chunkrust-analyzer cargo chunky-vec 0.1.0 Chunk#::availablerust-analyzer cargo chunky-vec 0.1.0 impl#[`Chunk<T>`]available().).unwrap_or_defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_default().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().0 {
170 self.chunksrust-analyzer cargo chunky-vec 0.1.0 ChunkyVec#chunks..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(Chunkrust-analyzer cargo chunky-vec 0.1.0 Chunk#::with_capacityrust-analyzer cargo chunky-vec 0.1.0 impl#[`Chunk<T>`]with_capacity().(Selfrust-analyzer cargo chunky-vec 0.1.0 impl#[`ChunkyVec<T>`]::DEFAULT_CAPACITYrust-analyzer cargo chunky-vec 0.1.0 impl#[`ChunkyVec<T>`]DEFAULT_CAPACITY.));
171 }
172 // Safety: Guaranteed to have a chunk with available elements
173 unsafe {
174 let last = self.chunksrust-analyzer cargo chunky-vec 0.1.0 ChunkyVec#chunks..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().1;
175 self.chunksrust-analyzer cargo chunky-vec 0.1.0 ChunkyVec#chunks..get_unchecked_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get_unchecked_mut().(last).push_getrust-analyzer cargo chunky-vec 0.1.0 impl#[`Chunk<T>`]push_get().(new_value)
176 }
177 }
178 }
179
180 impl<T> Indexrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#<usize> for ChunkyVecrust-analyzer cargo chunky-vec 0.1.0 ChunkyVec#<T> {
181 type Outputrust-analyzer cargo chunky-vec 0.1.0 impl#[`ChunkyVec<T>`][`Index<usize>`]Output# = T;
182
183 fn indexrust-analyzer cargo chunky-vec 0.1.0 impl#[`ChunkyVec<T>`][`Index<usize>`]index().(&self, index: usize) -> &Selfrust-analyzer cargo chunky-vec 0.1.0 impl#[`ChunkyVec<T>`][`Index<usize>`]::Outputrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#Output# {
184 self.getrust-analyzer cargo chunky-vec 0.1.0 impl#[`ChunkyVec<T>`]get().(index).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("index out of bounds")
185 }
186 }
187
188 impl<T> IndexMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#<usize> for ChunkyVecrust-analyzer cargo chunky-vec 0.1.0 ChunkyVec#<T> {
189 fn index_mutrust-analyzer cargo chunky-vec 0.1.0 impl#[`ChunkyVec<T>`][`IndexMut<usize>`]index_mut().(&mut self, index: usize) -> &mut Selfrust-analyzer cargo chunky-vec 0.1.0 impl#[`ChunkyVec<T>`][`IndexMut<usize>`]::Outputrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#Output# {
190 self.get_mutrust-analyzer cargo chunky-vec 0.1.0 impl#[`ChunkyVec<T>`]get_mut().(index).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("index out of bounds")
191 }
192 }
193
194 /// An iterator yielding shared references to the elements of a ChunkyVec.
195 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)]
196 pub struct Iterrust-analyzer cargo chunky-vec 0.1.0 Iter#<'a, T> {
197 /// Chunks iterator.
198 chunksrust-analyzer cargo chunky-vec 0.1.0 Iter#chunks.: slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/::Iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/Iter#<'a, Chunkrust-analyzer cargo chunky-vec 0.1.0 Chunk#<T>>,
199 /// Forward iterator for `next`.
200 iterrust-analyzer cargo chunky-vec 0.1.0 Iter#iter.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/::Iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/Iter#<'a, T>>,
201 /// Number of elements that are to be yielded by the iterator.
202 lenrust-analyzer cargo chunky-vec 0.1.0 Iter#len.: usize,
203 }
204
205 impl<'a, T> Iterrust-analyzer cargo chunky-vec 0.1.0 Iter#<'a, T> {
206 /// Creates a new iterator over the ChunkyVec
207 pub(craterust-analyzer cargo chunky-vec 0.1.0 crate/) fn newrust-analyzer cargo chunky-vec 0.1.0 impl#[`Iter<'a, T>`]new().(vec: &'a ChunkyVecrust-analyzer cargo chunky-vec 0.1.0 ChunkyVec#<T>) -> Selfrust-analyzer cargo chunky-vec 0.1.0 impl#[`Iter<'a, T>`] {
208 let len = vec.lenrust-analyzer cargo chunky-vec 0.1.0 impl#[`ChunkyVec<T>`]len().();
209 Selfrust-analyzer cargo chunky-vec 0.1.0 impl#[`Iter<'a, T>`] {
210 chunksrust-analyzer cargo chunky-vec 0.1.0 Iter#chunks.: vec.chunksrust-analyzer cargo chunky-vec 0.1.0 ChunkyVec#chunks..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().(),
211 iterrust-analyzer cargo chunky-vec 0.1.0 Iter#iter.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
212 lenrust-analyzer cargo chunky-vec 0.1.0 Iter#len.,
213 }
214 }
215 }
216
217 impl<'a, T> Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for Iterrust-analyzer cargo chunky-vec 0.1.0 Iter#<'a, T> {
218 type Itemrust-analyzer cargo chunky-vec 0.1.0 impl#[`Iter<'a, T>`][Iterator]Item# = &'a T;
219
220 fn nextrust-analyzer cargo chunky-vec 0.1.0 impl#[`Iter<'a, T>`][Iterator]next().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo chunky-vec 0.1.0 impl#[`Iter<'a, T>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> {
221 loop {
222 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ref mut iter) = self.iterrust-analyzer cargo chunky-vec 0.1.0 Iter#iter. {
223 if let front @ Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(_) = iter.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]next().() {
224 self.lenrust-analyzer cargo chunky-vec 0.1.0 Iter#len. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().1;
225 return front;
226 }
227 }
228 self.iterrust-analyzer cargo chunky-vec 0.1.0 Iter#iter. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(self.chunksrust-analyzer cargo chunky-vec 0.1.0 Iter#chunks..nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]next().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch()..iterrust-analyzer cargo chunky-vec 0.1.0 impl#[`Chunk<T>`]iter().());
229 }
230 }
231
232 fn size_hintrust-analyzer cargo chunky-vec 0.1.0 impl#[`Iter<'a, T>`][Iterator]size_hint().(&self) -> (usize, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>) {
233 (self.lenrust-analyzer cargo chunky-vec 0.1.0 impl#[`Iter<'a, T>`][ExactSizeIterator]len().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(self.lenrust-analyzer cargo chunky-vec 0.1.0 impl#[`Iter<'a, T>`][ExactSizeIterator]len().()))
234 }
235 }
236
237 impl<'a, T> ExactSizeIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/exact_size/ExactSizeIterator# for Iterrust-analyzer cargo chunky-vec 0.1.0 Iter#<'a, T> {
238 fn lenrust-analyzer cargo chunky-vec 0.1.0 impl#[`Iter<'a, T>`][ExactSizeIterator]len().(&self) -> usize {
239 self.lenrust-analyzer cargo chunky-vec 0.1.0 Iter#len.
240 }
241 }
242
243 /// An iterator yielding exclusive references to the elements of a ChunkVec.
244 pub struct IterMutrust-analyzer cargo chunky-vec 0.1.0 IterMut#<'a, T> {
245 /// Chunks iterator.
246 chunksrust-analyzer cargo chunky-vec 0.1.0 IterMut#chunks.: slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/::IterMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/IterMut#<'a, Chunkrust-analyzer cargo chunky-vec 0.1.0 Chunk#<T>>,
247 /// Forward iterator for `next`.
248 iterrust-analyzer cargo chunky-vec 0.1.0 IterMut#iter.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/::IterMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/IterMut#<'a, T>>,
249 /// Number of elements that are to be yielded by the iterator.
250 lenrust-analyzer cargo chunky-vec 0.1.0 IterMut#len.: usize,
251 }
252
253 impl<'a, T> IterMutrust-analyzer cargo chunky-vec 0.1.0 IterMut#<'a, T> {
254 /// Creates a new iterator over the bucket vector.
255 pub(craterust-analyzer cargo chunky-vec 0.1.0 crate/) fn newrust-analyzer cargo chunky-vec 0.1.0 impl#[`IterMut<'a, T>`]new().(vec: &'a mut ChunkyVecrust-analyzer cargo chunky-vec 0.1.0 ChunkyVec#<T>) -> Selfrust-analyzer cargo chunky-vec 0.1.0 impl#[`IterMut<'a, T>`] {
256 let len = vec.lenrust-analyzer cargo chunky-vec 0.1.0 impl#[`ChunkyVec<T>`]len().();
257 Selfrust-analyzer cargo chunky-vec 0.1.0 impl#[`IterMut<'a, T>`] {
258 chunksrust-analyzer cargo chunky-vec 0.1.0 IterMut#chunks.: vec.chunksrust-analyzer cargo chunky-vec 0.1.0 ChunkyVec#chunks..iter_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter_mut().(),
259 iterrust-analyzer cargo chunky-vec 0.1.0 IterMut#iter.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
260 lenrust-analyzer cargo chunky-vec 0.1.0 IterMut#len.,
261 }
262 }
263 }
264
265 impl<'a, T> Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for IterMutrust-analyzer cargo chunky-vec 0.1.0 IterMut#<'a, T> {
266 type Itemrust-analyzer cargo chunky-vec 0.1.0 impl#[`IterMut<'a, T>`][Iterator]Item# = &'a mut T;
267
268 fn nextrust-analyzer cargo chunky-vec 0.1.0 impl#[`IterMut<'a, T>`][Iterator]next().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo chunky-vec 0.1.0 impl#[`IterMut<'a, T>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> {
269 loop {
270 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ref mut iter) = self.iterrust-analyzer cargo chunky-vec 0.1.0 IterMut#iter. {
271 if let front @ Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(_) = iter.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`IterMut<'a, T>`][Iterator]next().() {
272 self.lenrust-analyzer cargo chunky-vec 0.1.0 IterMut#len. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().1;
273 return front;
274 }
275 }
276 self.iterrust-analyzer cargo chunky-vec 0.1.0 IterMut#iter. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(self.chunksrust-analyzer cargo chunky-vec 0.1.0 IterMut#chunks..nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`IterMut<'a, T>`][Iterator]next().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch()..iter_mutrust-analyzer cargo chunky-vec 0.1.0 impl#[`Chunk<T>`]iter_mut().());
277 }
278 }
279
280 fn size_hintrust-analyzer cargo chunky-vec 0.1.0 impl#[`IterMut<'a, T>`][Iterator]size_hint().(&self) -> (usize, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>) {
281 (self.lenrust-analyzer cargo chunky-vec 0.1.0 impl#[`IterMut<'a, T>`][ExactSizeIterator]len().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(self.lenrust-analyzer cargo chunky-vec 0.1.0 impl#[`IterMut<'a, T>`][ExactSizeIterator]len().()))
282 }
283 }
284
285 impl<'a, T> ExactSizeIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/exact_size/ExactSizeIterator# for IterMutrust-analyzer cargo chunky-vec 0.1.0 IterMut#<'a, T> {
286 fn lenrust-analyzer cargo chunky-vec 0.1.0 impl#[`IterMut<'a, T>`][ExactSizeIterator]len().(&self) -> usize {
287 self.lenrust-analyzer cargo chunky-vec 0.1.0 IterMut#len.
288 }
289 }
290 impl<'a, T> IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator# for &'a ChunkyVecrust-analyzer cargo chunky-vec 0.1.0 ChunkyVec#<T> {
291 type Itemrust-analyzer cargo chunky-vec 0.1.0 impl#[`&'a ChunkyVec<T>`][IntoIterator]Item# = &'a T;
292 type IntoIterrust-analyzer cargo chunky-vec 0.1.0 impl#[`&'a ChunkyVec<T>`][IntoIterator]IntoIter# = Iterrust-analyzer cargo chunky-vec 0.1.0 Iter#<'a, T>;
293
294 fn into_iterrust-analyzer cargo chunky-vec 0.1.0 impl#[`&'a ChunkyVec<T>`][IntoIterator]into_iter().(self) -> Iterrust-analyzer cargo chunky-vec 0.1.0 Iter#<'a, T> {
295 self.iterrust-analyzer cargo chunky-vec 0.1.0 impl#[`ChunkyVec<T>`]iter().()
296 }
297 }
298
299 impl<'a, T> IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator# for &'a mut ChunkyVecrust-analyzer cargo chunky-vec 0.1.0 ChunkyVec#<T> {
300 type Itemrust-analyzer cargo chunky-vec 0.1.0 impl#[`&'a mut ChunkyVec<T>`][IntoIterator]Item# = &'a mut T;
301 type IntoIterrust-analyzer cargo chunky-vec 0.1.0 impl#[`&'a mut ChunkyVec<T>`][IntoIterator]IntoIter# = IterMutrust-analyzer cargo chunky-vec 0.1.0 IterMut#<'a, T>;
302
303 fn into_iterrust-analyzer cargo chunky-vec 0.1.0 impl#[`&'a mut ChunkyVec<T>`][IntoIterator]into_iter().(self) -> IterMutrust-analyzer cargo chunky-vec 0.1.0 IterMut#<'a, T> {
304 self.iter_mutrust-analyzer cargo chunky-vec 0.1.0 impl#[`ChunkyVec<T>`]iter_mut().()
305 }
306 }
307
308 #[cfg(test)]
309 mod testsrust-analyzer cargo chunky-vec 0.1.0 tests/ {
310 use superrust-analyzer cargo chunky-vec 0.1.0 crate/::*;
311
312 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
313 fn iterate_emptyrust-analyzer cargo chunky-vec 0.1.0 tests/iterate_empty().() {
314 let v = ChunkyVecrust-analyzer cargo chunky-vec 0.1.0 ChunkyVec#::<usize>::defaultrust-analyzer cargo chunky-vec 0.1.0 impl#[`ChunkyVec<T>`][Default]default().();
315 for i in &v {
316 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{:?}", i);
317 }
318 }
319
320 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
321 fn iterate_multiple_chunksrust-analyzer cargo chunky-vec 0.1.0 tests/iterate_multiple_chunks().() {
322 let mut v = ChunkyVecrust-analyzer cargo chunky-vec 0.1.0 ChunkyVec#::<usize>::defaultrust-analyzer cargo chunky-vec 0.1.0 impl#[`ChunkyVec<T>`][Default]default().();
323 for i in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#33 {
324 v.pushrust-analyzer cargo chunky-vec 0.1.0 impl#[`ChunkyVec<T>`]push().(i);
325 }
326 let mut iter = v.iterrust-analyzer cargo chunky-vec 0.1.0 impl#[`ChunkyVec<T>`]iter().();
327 for _ in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#32 {
328 iter.nextrust-analyzer cargo chunky-vec 0.1.0 impl#[`Iter<'a, T>`][Iterator]next().();
329 }
330 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(iter.nextrust-analyzer cargo chunky-vec 0.1.0 impl#[`Iter<'a, T>`][Iterator]next().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&32));
331 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(iter.nextrust-analyzer cargo chunky-vec 0.1.0 impl#[`Iter<'a, T>`][Iterator]next().(), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
332 }
333
334 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
335 fn index_multiple_chunksrust-analyzer cargo chunky-vec 0.1.0 tests/index_multiple_chunks().() {
336 let mut v = ChunkyVecrust-analyzer cargo chunky-vec 0.1.0 ChunkyVec#::<usize>::defaultrust-analyzer cargo chunky-vec 0.1.0 impl#[`ChunkyVec<T>`][Default]default().();
337 for i in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#33 {
338 v.pushrust-analyzer cargo chunky-vec 0.1.0 impl#[`ChunkyVec<T>`]push().(i);
339 }
340 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(v.getrust-analyzer cargo chunky-vec 0.1.0 impl#[`ChunkyVec<T>`]get().(32), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&32));
341 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(v[rust-analyzer cargo chunky-vec 0.1.0 impl#[`ChunkyVec<T>`][`Index<usize>`]index().32]rust-analyzer cargo chunky-vec 0.1.0 impl#[`ChunkyVec<T>`][`Index<usize>`]index()., 32);
342 }
343 }