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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
use PhantomData;
/// This trait is used as a bound on generic mutability parameters.
///
/// This trait is implemented by two types, `Shared` and `Mutable`, and it is sealed so no other types may implement it.
///
/// Not to be confused with `MutabilityEnum<M>`, which represents a proof about a generic mutability parameter.
///
/// Note that while mutability parameters are implemented as type parameters, they represent an entirely different kind of generic parameter.
/// For this reason, the `M: Mutability` bound should be applied even in struct definitions where bounds are generally discouraged.
// SAFETY: this trait must only be implemented for `Shared` and `Mutable`. `Shared::mutability()` must return `MutabilityEnum::Shared(IsShared<Shared>)` and `Mutable::mutability()` must return `MutabilityEnum::Mutable(IsMutable<Mutable>)`.
pub unsafe
/// Represents the mutability of a shared reference, `&T`.
///
/// Along with `Mutable`, this is one of the two types that can be used as a generic mutability parameter.
/// It is an empty type because it is always used as a generic parameter and never as a value.
///
/// Just as with `&T`, interior mutability types may change while behind a reference of `Shared` mutability.
// SAFETY: `mutability()` does return `MutabilityEnum::Shared(IsShared<Shared>)`
unsafe
/// Represents the mutability of a mutable (unique) reference, `&mut T`.
///
/// Along with `Shared`, this is one of the two types that can be used as a generic mutability parameter.
/// It is an empty type because it is always used as a generic parameter and never as a value.
// SAFETY: `mutability()` does return `MutabilityEnum::Mutable(IsMutable<Mutable>)`
unsafe
/// The existence of a value of this type guarantees that a specific mutability parameter `M` is `Mutable`.
/// Unsafe code may rely on this guarantee.
/// You can obtain this value by matching over `M::mutability()`.
///
/// The most notable API that requires this is `GenRef::gen_{into,from}_mut`.
;
/// The existence of a value of this type guarantees that a specific mutability parameter `M` is `Shared`.
/// Unsafe code may rely on this guarantee.
/// You can obtain this value by matching over `M::mutability()`.
///
/// The most notable API that requires this is `GenRef::gen_{into,from}_shared`.
;
/// This enum makes it possible to `match` over a mutability parameter.
/// Not to be confused with the `Mutability` trait, which is used as a bound for mutability parameters; and `Shared` and `Mutable`, which are values of the mutability parameters.
///
/// A value of this type can be obtained from the `Mutability::mutability()` method.
///
/// Each variant contains a proof about the value of mutability parameter `M`.
///
/// Note that the only valid value of type `MutabilityEnum<Shared>` is `MutabilityEnum::Shared(IsShared)`, and the only value of type `MutabilityEnum<Mutable>` is `MutabilityEnum::Mutable(IsMutable)`