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
64
65
66
67
68
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<T: State> Binding<'_, T> {
pub fn new(o: &mut Object<T>) -> Self {
T::Lock(o.obj);
T::Bind(o.obj);
Self { t: Dummy }
}
pub fn zero() -> Self {
T::Lock(0);
T::Bind(0);
Self { t: Dummy }
}
}
impl<T: State> Drop for Binding<'_, 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)
}
}