1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
use super::state::*; use crate::uses::Dummy; #[derive(Debug)] pub struct Object<T: State> { t: Dummy<T>, pub obj: u32, } impl<T: State> Object<T> { pub fn new() -> Self { let obj = T::New(); Self { t: Dummy, obj } } } impl<T: State> Drop for Object<T> { fn drop(&mut self) { T::Drop(self.obj); } } impl<T: State> Default for Object<T> { fn default() -> Self { Self::new() } } pub struct Binding<'l, T: State> { t: Dummy<&'l T>, } impl<'l, T: State> Binding<'l, T> { pub fn new(o: &'l mut Object<T>) -> Self { T::Lock(o.obj); T::Bind(o.obj); Self { t: Dummy } } } impl<'l, T: State> Drop for Binding<'l, T> { fn drop(&mut self) { T::Unlock(); } } pub struct ArrObject<T: State, D> { t: Dummy<T>, d: Dummy<D>, pub obj: u32, pub len: usize, } impl<T: State, D> ArrObject<T, D> { pub fn new_empty(len: usize) -> Self { let (t, d, obj) = (Dummy, Dummy, T::New()); Self { t, d, obj, len } } } impl<T: State, D> Drop for ArrObject<T, D> { fn drop(&mut self) { T::Drop(self.obj); } } impl<T: State, D> Default for ArrObject<T, D> { fn default() -> Self { Self::new_empty(0) } }