#![cfg_attr(not(test), no_std)]
use allocator_api2::alloc::Allocator;
use combinator::{Cond, Fallback};
use core::{alloc::Layout, ptr::NonNull};
#[cfg(feature = "bumpalo")]
pub use bumpalo;
pub mod alloc;
pub mod combinator;
pub mod prelude {
pub use crate::{Allocandrescu as _, ArenaAllocator as _};
pub use allocator_api2::alloc::Allocator as _;
}
pub trait ArenaAllocator: Allocator {
fn contains(&self, ptr: NonNull<u8>, layout: Layout) -> bool;
}
impl<A> ArenaAllocator for &A
where
A: ArenaAllocator,
{
#[inline]
fn contains(&self, ptr: NonNull<u8>, layout: Layout) -> bool {
(*self).contains(ptr, layout)
}
}
pub trait Allocandrescu: Sized {
fn cond<F>(self, pred: F) -> Cond<Self, F>
where
F: Fn(Layout) -> bool,
{
Cond::new(self, pred)
}
fn fallback<S>(self, secondary: S) -> Fallback<Self, S>
where
Self: ArenaAllocator,
S: Allocator,
{
Fallback::new(self, secondary)
}
}
impl<A: Allocator> Allocandrescu for A {}