use core::fmt;
use core::marker::PhantomData;
use core::ptr::NonNull;
use crate::NonZeroLayout;
use crate::util::defaults;
#[derive(Clone, Copy, Default, Hash, PartialEq, Eq, PartialOrd, Ord)]
pub struct AllocTime<'lt> {
marker: PhantomData<&'lt fn(&'lt ())>,
}
#[deprecated = "Use the new name 'AllocTime' instead"]
pub type Invariant<'lt> = AllocTime<'lt>;
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct Allocation<'alloc> {
pub ptr: NonNull<u8>,
pub layout: NonZeroLayout,
pub lifetime: AllocTime<'alloc>,
}
pub unsafe trait LocalAlloc<'alloc> {
fn alloc(&'alloc self, layout: NonZeroLayout) -> Option<Allocation<'alloc>>;
unsafe fn dealloc(&'alloc self, alloc: Allocation<'alloc>);
fn alloc_zeroed(&'alloc self, layout: NonZeroLayout)
-> Option<Allocation<'alloc>>
{
defaults::local::alloc_zeroed(self, layout)
}
unsafe fn realloc(&'alloc self, alloc: Allocation<'alloc>, layout: NonZeroLayout)
-> Option<Allocation<'alloc>>
{
defaults::local::realloc(self, alloc, layout)
}
}
impl fmt::Debug for AllocTime<'_> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.pad("AllocTime")
}
}