use alloc::alloc::alloc;
use core::alloc::Layout;
use core::ptr::NonNull;
use crate::ArenaAlloc;
#[derive(Default)]
pub struct LeakingAlloc;
pub struct AllocErr;
impl ArenaAlloc for LeakingAlloc {
type Error = AllocErr;
fn try_alloc_layout(&self, layout: Layout) -> Result<NonNull<u8>, Self::Error> {
NonNull::new(unsafe { alloc(layout) }).ok_or(AllocErr)
}
}
pub struct FailingAlloc;
impl ArenaAlloc for FailingAlloc {
type Error = AllocErr;
fn try_alloc_layout(&self, _layout: Layout) -> Result<NonNull<u8>, Self::Error> {
Err(AllocErr)
}
}