use crate::SingleItemStorage;
#[cfg(feature = "alloc")]
use alloc::vec::Vec;
pub trait Get {
type Error;
type Input;
type Output<'output>
where
Self: 'output;
fn get(&self, input: Self::Input) -> Result<Self::Output<'_>, Self::Error>;
}
impl<T> Get for SingleItemStorage<T> {
type Error = crate::Error;
type Input = usize;
type Output<'output> = &'output T
where
Self: 'output;
#[inline]
fn get(&self, _: Self::Input) -> Result<Self::Output<'_>, Self::Error> {
_get!(self.as_ref(), 0)
}
}
impl<T, const N: usize> Get for [T; N] {
type Error = crate::Error;
type Input = usize;
type Output<'output> = &'output T
where
Self: 'output;
#[inline]
fn get(&self, input: Self::Input) -> Result<Self::Output<'_>, Self::Error> {
_get!(self.as_ref(), input)
}
}
impl<T> Get for &'_ [T] {
type Error = crate::Error;
type Input = usize;
type Output<'output> = &'output T
where
Self: 'output;
#[inline]
fn get(&self, input: Self::Input) -> Result<Self::Output<'_>, Self::Error> {
_get!(self.as_ref(), input)
}
}
impl<T> Get for &'_ mut [T] {
type Error = crate::Error;
type Input = usize;
type Output<'output> = &'output T
where
Self: 'output;
#[inline]
fn get(&self, input: Self::Input) -> Result<Self::Output<'_>, Self::Error> {
_get!(self.as_ref(), input)
}
}
#[cfg(feature = "alloc")]
impl<T> Get for Vec<T> {
type Error = crate::Error;
type Input = usize;
type Output<'output> = &'output T
where
Self: 'output;
#[inline]
fn get(&self, input: Self::Input) -> Result<Self::Output<'_>, Self::Error> {
_get!(self.as_slice(), input)
}
}
#[cfg(feature = "arrayvec")]
impl<T, const N: usize> Get for arrayvec::ArrayVec<T, N> {
type Error = crate::Error;
type Input = usize;
type Output<'output> = &'output T
where
Self: 'output;
#[inline]
fn get(&self, input: Self::Input) -> Result<Self::Output<'_>, Self::Error> {
_get!(self.as_ref(), input)
}
}
#[cfg(feature = "smallvec")]
impl<A> Get for smallvec::SmallVec<A>
where
A: smallvec::Array,
{
type Error = crate::Error;
type Input = usize;
type Output<'output> = &'output A::Item
where
Self: 'output;
#[inline]
fn get(&self, input: Self::Input) -> Result<Self::Output<'_>, Self::Error> {
_get!(self.as_ref(), input)
}
}
#[cfg(feature = "staticvec")]
impl<T, const N: usize> Get for staticvec::StaticVec<T, N> {
type Error = crate::Error;
type Input = usize;
type Output<'output> = &'output T
where
Self: 'output,
T: 'output;
#[inline]
fn get(&self, input: Self::Input) -> Result<Self::Output<'_>, Self::Error> {
_get!(self.as_ref(), input)
}
}
#[cfg(feature = "tinyvec")]
impl<A> Get for tinyvec::ArrayVec<A>
where
A: tinyvec::Array,
A::Item: Default,
{
type Error = crate::Error;
type Input = usize;
type Output<'output> = &'output A::Item
where
Self: 'output;
#[inline]
fn get(&self, input: Self::Input) -> Result<Self::Output<'_>, Self::Error> {
_get!(self.as_ref(), input)
}
}
#[cfg(feature = "tinyvec")]
impl<A> Get for tinyvec::TinyVec<A>
where
A: tinyvec::Array,
A::Item: Default,
{
type Error = crate::Error;
type Input = usize;
type Output<'output> = &'output A::Item
where
Self: 'output;
#[inline]
fn get(&self, input: Self::Input) -> Result<Self::Output<'_>, Self::Error> {
_get!(self.as_ref(), input)
}
}