#[cfg(feature="alloc")]
mod heap;
mod stack;
mod stack_n;
mod empty;
#[cfg(feature="alloc")]
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
pub use heap::Heap;
pub use stack::Stack;
pub use stack_n::StackN;
pub use empty::Empty;
#[cfg(feature="alloc")]
pub(crate) type Default = Heap;
#[cfg(not(feature="alloc"))]
pub(crate) type Default = Empty;
use core::alloc::Layout;
use core::ptr::NonNull;
pub trait MemBuilder: Clone {
type Mem: Mem;
fn build(&mut self, element_layout: Layout) -> Self::Mem;
}
pub trait MemBuilderSizeable: MemBuilder{
fn build_with_size(&mut self, element_layout: Layout, capacity: usize) -> Self::Mem;
}
pub trait Mem{
fn as_ptr(&self) -> *const u8;
fn as_mut_ptr(&mut self) -> *mut u8;
fn element_layout(&self) -> Layout;
fn size(&self) -> usize;
fn expand(&mut self, additional: usize){
let _ = additional;
panic!("Can't change capacity!");
}
}
pub trait MemResizable: Mem{
fn expand_exact(&mut self, additional: usize){
self.resize(self.size() + additional);
}
fn resize(&mut self, new_size: usize);
}
pub trait MemRawParts: Mem{
type Handle;
fn into_raw_parts(self) -> (Self::Handle, Layout, usize);
unsafe fn from_raw_parts(handle: Self::Handle, element_layout: Layout, size: usize) -> Self;
}
#[inline]
const fn dangling(layout: &Layout) -> NonNull<u8>{
#[cfg(miri)]
{
layout.dangling()
}
#[cfg(not(miri))]
{
unsafe { NonNull::new_unchecked(layout.align() as *mut u8) }
}
}