use super::state::*; use crate::stdlib::*; #[derive(Debug)] pub struct Object { t: Dummy, pub obj: u32, } impl Object { pub fn new() -> Self { let obj = T::New(); Self { t: Dummy, obj } } } impl Drop for Object { fn drop(&mut self) { T::Drop(self.obj); } } impl Default for Object { fn default() -> Self { Self::new() } } pub struct Binding<'l, T: State>(Dummy<&'l T>); impl Binding<'_, T> { pub fn new(o: &Object) -> Self { T::Lock(o.obj); T::Bind(o.obj); Self(Dummy) } pub fn zero() -> Self { T::Lock(0); T::Bind(0); Self(Dummy) } } impl Drop for Binding<'_, T> { fn drop(&mut self) { T::Unlock(); } } #[derive(Debug)] pub struct ArrObject { t: Dummy, d: Dummy, pub obj: u32, pub len: usize, } impl ArrObject { pub fn new_empty(len: usize) -> Self { let (t, d, obj) = (Dummy, Dummy, T::New()); Self { t, d, obj, len } } pub fn size(&self) -> usize { self.len * type_size::() } } impl Drop for ArrObject { fn drop(&mut self) { T::Drop(self.obj); } } impl Default for ArrObject { fn default() -> Self { Self::new_empty(0) } }