use bumpalo::Bump;
pub struct Arena {
bump: Bump,
}
impl Arena {
pub fn new() -> Self { Self { bump: Bump::new() } }
pub fn with_capacity(capacity: usize) -> Self { Self { bump: Bump::with_capacity(capacity) } }
pub fn reset(&mut self) { self.bump.reset(); }
pub fn alloc<T>(&self, val: T) -> &mut T { self.bump.alloc(val) }
pub fn alloc_slice_copy<T: Copy>(&self, slice: &[T]) -> &mut [T] { self.bump.alloc_slice_copy(slice) }
pub fn allocated_bytes(&self) -> usize { self.bump.allocated_bytes() }
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn alloc_and_reset() {
let mut arena = Arena::with_capacity(1024);
let _ = arena.alloc(42i64);
let before = arena.allocated_bytes();
assert!(before > 0);
arena.reset();
let _ = arena.alloc(99i64);
assert!(arena.allocated_bytes() >= before);
}
}