use std::ops::{Index, IndexMut};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct View<'a, T> {
data: &'a [T],
}
impl<'a, T> View<'a, T> {
#[inline]
pub fn new(data: &'a [T]) -> Self {
Self { data }
}
#[inline]
pub fn len(&self) -> usize {
self.data.len()
}
#[inline]
pub fn is_empty(&self) -> bool {
self.data.is_empty()
}
#[inline]
pub fn as_slice(&self) -> &'a [T] {
self.data
}
}
impl<'a, T> Index<usize> for View<'a, T> {
type Output = T;
#[inline]
fn index(&self, index: usize) -> &Self::Output {
&self.data[index]
}
}
#[derive(Debug, PartialEq, Eq)]
pub struct ViewMut<'a, T> {
data: &'a mut [T],
}
impl<'a, T> ViewMut<'a, T> {
#[inline]
pub fn new(data: &'a mut [T]) -> Self {
Self { data }
}
#[inline]
pub fn len(&self) -> usize {
self.data.len()
}
#[inline]
pub fn is_empty(&self) -> bool {
self.data.is_empty()
}
#[inline]
pub fn as_slice(&self) -> &[T] {
self.data
}
#[inline]
pub fn as_mut_slice(&mut self) -> &mut [T] {
self.data
}
}
impl<'a, T> Index<usize> for ViewMut<'a, T> {
type Output = T;
#[inline]
fn index(&self, index: usize) -> &Self::Output {
&self.data[index]
}
}
impl<'a, T> IndexMut<usize> for ViewMut<'a, T> {
#[inline]
fn index_mut(&mut self, index: usize) -> &mut Self::Output {
&mut self.data[index]
}
}