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
use core::fmt::Debug;
use core::hash::Hash;
use core::panic::{RefUnwindSafe, UnwindSafe};
use super::AutoreleaseSafe;
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
enum Never {}
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
pub struct Owned {
inner: Never,
}
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
pub struct Shared {
inner: Never,
}
mod private {
pub trait Sealed {}
impl Sealed for super::Owned {}
impl Sealed for super::Shared {}
}
pub trait Ownership:
private::Sealed
+ 'static
+ Sized
+ Send
+ Sync
+ Unpin
+ UnwindSafe
+ RefUnwindSafe
+ Clone
+ Copy
+ PartialEq
+ Eq
+ PartialOrd
+ Ord
+ Hash
+ Debug
+ AutoreleaseSafe
{
}
impl Ownership for Owned {}
impl Ownership for Shared {}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_generic_ownership_traits() {
fn assert_partialeq<T: PartialEq>() {}
assert_partialeq::<Shared>();
assert_partialeq::<Owned>();
fn test_ownership_implies_partialeq<O: Ownership>() {
assert_partialeq::<O>();
}
test_ownership_implies_partialeq::<Shared>();
test_ownership_implies_partialeq::<Owned>();
}
}