use core::ptr::Thin;
pub const trait AsSlice
{
type Elem: Sized + Thin;
fn as_slice(&self) -> &[Self::Elem];
fn as_mut_slice(&mut self) -> &mut [Self::Elem];
}
impl<T> const AsSlice for [T]
{
type Elem = T;
fn as_slice(&self) -> &[Self::Elem]
{
self
}
fn as_mut_slice(&mut self) -> &mut [Self::Elem]
{
self
}
}
impl<T, const N: usize> const AsSlice for [T; N]
{
type Elem = T;
fn as_slice(&self) -> &[Self::Elem]
{
self.as_slice()
}
fn as_mut_slice(&mut self) -> &mut [Self::Elem]
{
self.as_mut_slice()
}
}
#[cfg(feature = "alloc")]
impl<T, A> const AsSlice for alloc::vec::Vec<T, A>
where
A: core::alloc::Allocator
{
type Elem = T;
fn as_slice(&self) -> &[Self::Elem]
{
self.as_slice()
}
fn as_mut_slice(&mut self) -> &mut [Self::Elem]
{
self.as_mut_slice()
}
}
#[cfg(feature = "alloc")]
impl<T, A> const AsSlice for alloc::boxed::Box<T, A>
where
A: core::alloc::Allocator,
T: ~const AsSlice + ?Sized
{
type Elem = T::Elem;
fn as_slice(&self) -> &[Self::Elem]
{
(**self).as_slice()
}
fn as_mut_slice(&mut self) -> &mut [Self::Elem]
{
(**self).as_mut_slice()
}
}