#![deny(missing_docs)]
#![deny(clippy::all)]
use std::ops::{Index, IndexMut};
pub struct Wrapping<'a, T>(&'a [T]);
impl<'a, T> Index<usize> for Wrapping<'a, T> {
type Output = T;
fn index(&self, idx: usize) -> &T {
&self.0[idx % self.0.len()]
}
}
impl<'a, T, I: Into<&'a [T]>> From<I> for Wrapping<'a, T> {
fn from(into: I) -> Self {
Self(into.into())
}
}
pub struct MutWrapping<'a, T>(&'a mut [T]);
impl<'a, T> Index<usize> for MutWrapping<'a, T> {
type Output = T;
fn index(&self, idx: usize) -> &T {
&self.0[idx % self.0.len()]
}
}
impl<'a, T> IndexMut<usize> for MutWrapping<'a, T> {
fn index_mut(&mut self, idx: usize) -> &mut T {
&mut self.0[idx % self.0.len()]
}
}
impl<'a, T, I: Into<&'a mut [T]>> From<I> for MutWrapping<'a, T> {
fn from(into: I) -> Self {
Self(into.into())
}
}