@@ -118,17 +118,17 @@ impl PrivilegeLevel {
118
118
119
119
/// A wrapper that can be used to safely create one mutable reference `&'static mut T` from a static variable.
120
120
///
121
- /// `Singleton ` is safe because it ensures that it only ever gives out one reference.
121
+ /// `SingleUseCell ` is safe because it ensures that it only ever gives out one reference.
122
122
///
123
- /// ``Singleton <T>` is a safe alternative to `static mut` or a static `UnsafeCell<T>`.
123
+ /// ``SingleUseCell <T>` is a safe alternative to `static mut` or a static `UnsafeCell<T>`.
124
124
#[ derive( Debug ) ]
125
- pub struct Singleton < T > {
125
+ pub struct SingleUseCell < T > {
126
126
used : AtomicBool ,
127
127
value : UnsafeCell < T > ,
128
128
}
129
129
130
- impl < T > Singleton < T > {
131
- /// Construct a new singleton .
130
+ impl < T > SingleUseCell < T > {
131
+ /// Construct a new SingleUseCell .
132
132
pub const fn new ( value : T ) -> Self {
133
133
Self {
134
134
used : AtomicBool :: new ( false ) ,
@@ -141,9 +141,9 @@ impl<T> Singleton<T> {
141
141
/// called and fail on all following calls.
142
142
///
143
143
/// ```
144
- /// use x86_64::Singleton ;
144
+ /// use x86_64::SingleUseCell ;
145
145
///
146
- /// static FOO: Singleton <i32> = Singleton ::new(0);
146
+ /// static FOO: SingleUseCell <i32> = SingleUseCell ::new(0);
147
147
///
148
148
/// // Call `try_get_mut` for the first time and get a reference.
149
149
/// let first: &'static mut i32 = FOO.try_get_mut().unwrap();
@@ -165,9 +165,9 @@ impl<T> Singleton<T> {
165
165
}
166
166
}
167
167
168
- // SAFETY: Sharing a `Singleton <T>` between threads is safe regardless of whether `T` is `Sync`
168
+ // SAFETY: Sharing a `SingleUseCell <T>` between threads is safe regardless of whether `T` is `Sync`
169
169
// because we only expose the inner value once to one thread.
170
- unsafe impl < T > Sync for Singleton < T > { }
170
+ unsafe impl < T > Sync for SingleUseCell < T > { }
171
171
172
- // SAFETY: It's safe to send a `Singleton <T>` to another thread if it's safe to send `T`.
173
- unsafe impl < T : Send > Send for Singleton < T > { }
172
+ // SAFETY: It's safe to send a `SingleUseCell <T>` to another thread if it's safe to send `T`.
173
+ unsafe impl < T : Send > Send for SingleUseCell < T > { }
0 commit comments