refraction_types/
ring_iter.rs1use std::iter::Chain;
2
3use crate::ring_buffer::BoundedRingBuffer;
4
5pub struct IntoIter<T>(pub BoundedRingBuffer<T>);
9
10pub struct Iter<'a, T>(pub Chain<std::slice::Iter<'a, T>, std::slice::Iter<'a, T>>);
15
16pub struct IterMut<'a, T>(pub Chain<std::slice::IterMut<'a, T>, std::slice::IterMut<'a, T>>);
21
22impl<T> Iterator for IntoIter<T>
23where
24 T: Copy + Default,
25{
26 type Item = T;
27
28 fn next(&mut self) -> Option<Self::Item> {
29 self.0.dequeue()
30 }
31
32 fn size_hint(&self) -> (usize, Option<usize>) {
33 (self.0.len, Some(self.0.len))
34 }
35}
36
37impl<'a, T> Iterator for Iter<'a, T>
38where
39 T: Copy + Default,
40{
41 type Item = &'a T;
42
43 fn next(&mut self) -> Option<Self::Item> {
44 self.0.next()
45 }
46}
47
48impl<'a, T> Iterator for IterMut<'a, T>
49where
50 T: Copy + Default,
51{
52 type Item = &'a mut T;
53
54 fn next(&mut self) -> Option<Self::Item> {
55 self.0.next()
56 }
57}