mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 23:04:33 +00:00
parent
c3364780d2
commit
578e714393
@ -6,6 +6,7 @@ mod tests;
|
||||
use crate::{
|
||||
cell::{Cell, UnsafeCell},
|
||||
fmt,
|
||||
marker::PhantomData,
|
||||
mem::{self, MaybeUninit},
|
||||
ops::{Deref, Drop},
|
||||
panic::{RefUnwindSafe, UnwindSafe},
|
||||
@ -46,6 +47,8 @@ pub struct SyncOnceCell<T> {
|
||||
once: Once,
|
||||
// Whether or not the value is initialized is tracked by `state_and_queue`.
|
||||
value: UnsafeCell<MaybeUninit<T>>,
|
||||
// Make sure dropck understands we're dropping T in our Drop impl.
|
||||
_marker: PhantomData<T>,
|
||||
}
|
||||
|
||||
// Why do we need `T: Send`?
|
||||
@ -119,7 +122,11 @@ impl<T> SyncOnceCell<T> {
|
||||
/// Creates a new empty cell.
|
||||
#[unstable(feature = "once_cell", issue = "74465")]
|
||||
pub const fn new() -> SyncOnceCell<T> {
|
||||
SyncOnceCell { once: Once::new(), value: UnsafeCell::new(MaybeUninit::uninit()) }
|
||||
SyncOnceCell {
|
||||
once: Once::new(),
|
||||
value: UnsafeCell::new(MaybeUninit::uninit()),
|
||||
_marker: PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
/// Gets the reference to the underlying value.
|
||||
|
Loading…
Reference in New Issue
Block a user