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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
use std::{
fmt::{self, Debug, Formatter},
sync::Arc,
};
#[derive(Debug)]
pub struct InstanceId {
inner: Arc<u8>,
msg: &'static str,
}
impl InstanceId {
pub fn new(msg: &'static str) -> Self {
InstanceId {
inner: Arc::default(),
msg,
}
}
#[inline]
pub fn as_usize(&self) -> usize {
self.inner.as_ref() as *const _ as usize
}
#[inline]
pub fn assert_eq(&self, reference: &Reference) {
assert_eq!(self, reference, "{}", self.msg);
}
#[inline]
pub fn reference(&self) -> Reference {
Reference {
inner: self.inner.clone(),
}
}
}
impl PartialEq<Reference> for InstanceId {
#[inline]
fn eq(&self, reference: &Reference) -> bool {
self.as_usize() == reference.as_usize()
}
}
#[derive(Debug, Default)]
pub struct Reference {
inner: Arc<u8>,
}
impl Reference {
#[inline]
pub fn as_usize(&self) -> usize {
self.inner.as_ref() as *const _ as usize
}
}
impl Eq for Reference {}
impl PartialEq for Reference {
fn eq(&self, other: &Reference) -> bool {
self.as_usize() == other.as_usize()
}
}
pub struct NoSharedAccess<T>(T);
impl<T> NoSharedAccess<T> {
pub fn new(t: T) -> Self {
NoSharedAccess(t)
}
pub fn get_mut(&mut self) -> &mut T {
&mut self.0
}
}
impl<T> Debug for NoSharedAccess<T>
where
T: Debug,
{
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
self.0.fmt(f)
}
}
unsafe impl<T> Sync for NoSharedAccess<T> where for<'a> &'a mut NoSharedAccess<T>: Send {}