use bumpalo::{
Bump,
collections::{CollectIn, Vec as BumpVec},
};
#[derive(Debug, Default)]
pub struct Arena(Bump);
impl Arena {
#[inline]
pub fn new() -> Self {
Self::default()
}
#[inline]
pub(crate) fn alloc<T: Copy>(&self, value: T) -> &mut T {
self.0.alloc(value)
}
#[inline]
pub(crate) fn alloc_slice_copy<T: Copy>(&self, slice: &[T]) -> &mut [T] {
self.0.alloc_slice_copy(slice)
}
#[inline]
pub(crate) fn alloc_slice_exact<I>(&self, iter: I) -> &mut [I::Item]
where
I: IntoIterator,
I::IntoIter: ExactSizeIterator,
I::Item: Copy,
{
self.0.alloc_slice_fill_iter(iter)
}
#[inline]
pub(crate) fn alloc_slice<I: IntoIterator>(&self, iter: I) -> &mut [I::Item]
where
I::Item: Copy,
{
iter.into_iter()
.collect_in::<BumpVec<_>>(&self.0)
.into_bump_slice_mut()
}
#[inline]
pub(crate) fn alloc_str(&self, s: &str) -> &mut str {
self.0.alloc_str(s)
}
}