use std::alloc::{GlobalAlloc, Layout, System};
pub struct LingBox<T>(Box<T>);
impl<T> LingBox<T> {
pub fn new(val: T) -> Self { Self(Box::new(val)) }
pub fn into_inner(self) -> T { *self.0 }
}
impl<T> std::ops::Deref for LingBox<T> {
type Target = T;
fn deref(&self) -> &T { &self.0 }
}
impl<T> std::ops::DerefMut for LingBox<T> {
fn deref_mut(&mut self) -> &mut T { &mut self.0 }
}
impl<T: std::fmt::Debug> std::fmt::Debug for LingBox<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "LingBox({:?})", &*self.0)
}
}
pub unsafe fn raw_alloc(size: usize, align: usize) -> *mut u8 {
let layout = Layout::from_size_align_unchecked(size, align);
System.alloc(layout)
}
pub unsafe fn raw_dealloc(ptr: *mut u8, size: usize, align: usize) {
let layout = Layout::from_size_align_unchecked(size, align);
System.dealloc(ptr, layout)
}