1use crate::{Slice, SliceBorrowed, SliceMut, SliceOwned};
2
3pub struct Cycle<S>(pub S);
5
6impl<S> Slice for Cycle<S>
7where
8 S: Slice,
9{
10 type Output = S::Output;
11
12 fn len(&self) -> usize {
13 usize::MAX
14 }
15
16 fn get_with<F: FnMut(&Self::Output) -> U, U>(&self, index: usize, f: &mut F) -> Option<U> {
17 self.0.get_with(index % self.0.len(), f)
18 }
19}
20
21impl<S> SliceOwned for Cycle<S>
22where
23 S: SliceOwned,
24{
25 fn get_owned(&self, index: usize) -> Option<Self::Output> {
26 self.0.get_owned(index % self.0.len())
27 }
28}
29
30impl<S> SliceBorrowed for Cycle<S>
31where
32 S: SliceBorrowed,
33{
34 fn get(&self, index: usize) -> Option<&Self::Output> {
35 self.0.get(index % self.0.len())
36 }
37}
38
39impl<S> SliceMut for Cycle<S>
40where
41 S: SliceMut,
42{
43 fn get_mut(&mut self, index: usize) -> Option<&mut Self::Output> {
44 self.0.get_mut(index % self.0.len())
45 }
46}