Struct std::cell::SyncUnsafeCell
source · #[repr(transparent)]pub struct SyncUnsafeCell<T>where
T: ?Sized,{ /* private fields */ }🔬This is a nightly-only experimental API. (
sync_unsafe_cell #95439)Expand description
UnsafeCell,但是 Sync。
这只是一个 UnsafeCell,但如果 T 实现了 Sync,则它也就实现了 Sync。
UnsafeCell 没有实现 Sync,以防止意外误用。
如果有意的话,您可以使用 SyncUnsafeCell 而不是 UnsafeCell 来允许它在线程之间共享。
提供适当的同步仍然是用户的任务,因此使用这种类型同样不安全。
有关详细信息,请参见 UnsafeCell。
Implementations§
source§impl<T> SyncUnsafeCell<T>
impl<T> SyncUnsafeCell<T>
sourcepub const fn new(value: T) -> SyncUnsafeCell<T>
🔬This is a nightly-only experimental API. (sync_unsafe_cell #95439)
pub const fn new(value: T) -> SyncUnsafeCell<T>
sync_unsafe_cell #95439)创建一个新的 SyncUnsafeCell 实例,它将包装指定的值。
sourcepub const fn into_inner(self) -> T
🔬This is a nightly-only experimental API. (sync_unsafe_cell #95439)
pub const fn into_inner(self) -> T
sync_unsafe_cell #95439)解开值,消耗 cell。
source§impl<T> SyncUnsafeCell<T>where
T: ?Sized,
impl<T> SyncUnsafeCell<T>where T: ?Sized,
sourcepub const fn get(&self) -> *mut T
🔬This is a nightly-only experimental API. (sync_unsafe_cell #95439)
pub const fn get(&self) -> *mut T
sync_unsafe_cell #95439)获取指向包装值的可变指针。
可以将其强制转换为任何类型的指针。
强制转换为 &mut T 时,访问是唯一的 (无活跃的引用,可变或不活动),并确保转换为 &T 时没有发生任何可变的或可变别名。
sourcepub const fn get_mut(&mut self) -> &mut T
🔬This is a nightly-only experimental API. (sync_unsafe_cell #95439)
pub const fn get_mut(&mut self) -> &mut T
sync_unsafe_cell #95439)返回对底层数据的可变引用。
这个调用(在编译时)可变地借用了 SyncUnsafeCell,这保证了我们拥有唯一的引用。
sourcepub const fn raw_get(this: *const SyncUnsafeCell<T>) -> *mut T
🔬This is a nightly-only experimental API. (sync_unsafe_cell #95439)
pub const fn raw_get(this: *const SyncUnsafeCell<T>) -> *mut T
sync_unsafe_cell #95439)获取指向包装值的可变指针。
有关详细信息,请参见 UnsafeCell::get。
Trait Implementations§
source§impl<T> Debug for SyncUnsafeCell<T>where
T: ?Sized,
impl<T> Debug for SyncUnsafeCell<T>where T: ?Sized,
source§impl<T> Default for SyncUnsafeCell<T>where
T: Default,
impl<T> Default for SyncUnsafeCell<T>where T: Default,
source§fn default() -> SyncUnsafeCell<T>
fn default() -> SyncUnsafeCell<T>
使用 T 的 Default 值创建一个 SyncUnsafeCell。
source§impl<T> From<T> for SyncUnsafeCell<T>
impl<T> From<T> for SyncUnsafeCell<T>
source§fn from(t: T) -> SyncUnsafeCell<T>
fn from(t: T) -> SyncUnsafeCell<T>
创建一个包含给定值的新 SyncUnsafeCell<T>。