pub(crate) mod linear_storage_len;
pub(crate) mod linear_storage_mut;
pub(crate) mod linear_storage_slice;
use core::mem::needs_drop;
pub(crate) trait LinearStorage<T> {
const NEEDS_DROP: bool = needs_drop::<T>();
type Len: linear_storage_len::LinearStorageLen;
type Slice: linear_storage_slice::LinearStorageSlice<Data = T> + ?Sized;
fn as_ptr(&self) -> *const T;
fn capacity(&self) -> Self::Len;
fn len(&self) -> Self::Len;
#[inline]
fn as_slice(&self) -> &Self::Slice {
use linear_storage_len::LinearStorageLen as _;
use linear_storage_slice::LinearStorageSlice as _;
unsafe { Self::Slice::from_raw_parts(self.as_ptr(), self.len().usize()) }
}
#[inline]
fn remaining(&self) -> Self::Len {
use linear_storage_len::LinearStorageLen as _;
self.capacity().wrapping_sub(self.len())
}
}
impl<T> LinearStorage<T> for alloc::vec::Vec<T> {
type Len = usize;
type Slice = [T];
#[inline]
fn as_ptr(&self) -> *const T {
(*self).as_ptr()
}
#[inline]
fn capacity(&self) -> Self::Len {
(*self).capacity()
}
#[inline]
fn len(&self) -> Self::Len {
(*self).len()
}
}