use std::slice::SliceIndex;
pub trait Array {
type Element;
#[must_use]
fn get<I>(&self, i: I) -> Option<&<I as SliceIndex<[Self::Element]>>::Output>
where
I: SliceIndex<[Self::Element]>;
#[must_use]
fn iter<'i>(&'i self) -> Box<dyn Iterator<Item = &Self::Element> + 'i>;
#[must_use]
fn len(&self) -> usize;
#[must_use]
fn is_empty(&self) -> bool {
self.len() == 0
}
}
pub trait ArrayMut {
type Element;
#[must_use]
fn get_mut(&mut self, i: usize) -> Option<&mut Self::Element>;
#[must_use]
fn pop(&mut self) -> Option<Self::Element>;
fn push(&mut self, e: Self::Element);
}
impl<T> Array for Vec<T> {
type Element = T;
#[inline]
fn get<I>(&self, i: I) -> Option<&<I as SliceIndex<[T]>>::Output>
where
I: SliceIndex<[T]>,
{
<[T]>::get(self, i)
}
fn iter<'i>(&'i self) -> Box<dyn Iterator<Item = &T> + 'i> {
Box::new(<[T]>::iter(self))
}
#[inline]
fn len(&self) -> usize {
self.len()
}
}
impl<T> ArrayMut for Vec<T> {
type Element = T;
#[inline]
fn get_mut(&mut self, i: usize) -> Option<&mut T> {
<[T]>::get_mut(self, i)
}
#[inline]
fn pop(&mut self) -> Option<T> {
Vec::pop(self)
}
#[inline]
fn push(&mut self, e: T) {
Vec::push(self, e);
}
}
#[cfg(feature = "c-abi")]
impl<T> Array for abi_stable::std_types::RVec<T> {
type Element = T;
#[inline]
fn get<I>(&self, i: I) -> Option<&<I as SliceIndex<[T]>>::Output>
where
I: SliceIndex<[T]>,
{
<[T]>::get(self, i)
}
fn iter<'i>(&'i self) -> Box<dyn Iterator<Item = &T> + 'i> {
Box::new(<[T]>::iter(self))
}
#[inline]
fn len(&self) -> usize {
self.len()
}
}
#[cfg(feature = "c-abi")]
impl<T> ArrayMut for abi_stable::std_types::RVec<T> {
type Element = T;
#[inline]
fn get_mut(&mut self, i: usize) -> Option<&mut T> {
<[T]>::get_mut(self, i)
}
#[inline]
fn pop(&mut self) -> Option<T> {
abi_stable::std_types::RVec::pop(self)
}
#[inline]
fn push(&mut self, e: T) {
abi_stable::std_types::RVec::push(self, e);
}
}