use core::{ops::Deref, ptr};
use crate::Arena;
#[derive(Debug)]
pub struct Box<'a, T>(&'a mut T);
impl<'a, T> Box<'a, T> {
pub fn new_in<const N: usize>(x: T, arena: &'a Arena<T, N>) -> Result<Self, T> {
arena.alloc(x).map(Self)
}
}
impl<'a, T> Deref for Box<'a, T> {
type Target = T;
fn deref(&self) -> &Self::Target {
&*self.0
}
}
impl<'a, 'b, T: PartialEq> PartialEq<Box<'b, T>> for Box<'a, T> {
fn eq(&self, other: &Box<'b, T>) -> bool {
PartialEq::eq(&**self, &**other)
}
fn ne(&self, other: &Box<'b, T>) -> bool {
PartialEq::ne(&**self, &**other)
}
}
impl<'a, T> Drop for Box<'a, T> {
fn drop(&mut self) {
unsafe { ptr::drop_in_place(self.0) }
}
}