wrapping 0.1.2

Wrapping slices and arrays
Documentation
use generic_array::{ArrayLength, GenericArray};
use std::ops::{Deref, Index, IndexMut};

/// An array that wraps around its size.
///
/// # Example
/// ```
/// use wrapping::WrappingArray;
///
/// let array: [&str; 1] = ["hello"];
/// let wrapping = WrappingArray::from(array);
///
/// assert_eq!(wrapping[0], "hello");
/// assert_eq!(wrapping[1], "hello");
/// ```
pub struct WrappingArray<T, N: ArrayLength<T>>(GenericArray<T, N>);

impl<T, N: ArrayLength<T>, I: Into<GenericArray<T, N>>> From<I>
    for WrappingArray<T, N>
{
    fn from(array: I) -> Self {
        WrappingArray(array.into())
    }
}

impl<T, N: ArrayLength<T>> Deref for WrappingArray<T, N> {
    type Target = GenericArray<T, N>;

    fn deref(&self) -> &Self::Target {
        &self.0
    }
}

impl<T, N: ArrayLength<T>> Index<usize> for WrappingArray<T, N> {
    type Output = T;

    fn index(&self, index: usize) -> &Self::Output {
        &self.0[index % self.0.len()]
    }
}

impl<T, N: ArrayLength<T>> IndexMut<usize> for WrappingArray<T, N> {
    fn index_mut(&mut self, index: usize) -> &mut Self::Output {
        let len = self.0.len();
        &mut self.0[index % len]
    }
}