pub struct UnsafeSendSync<T: ?Sized>(/* private fields */);Expand description
A wrapper that unsafely makes T Send + Sync without requiring it for T.
Construction of this type is unsafe, as the caller must ensure that every use of the resulting value is indeed thread-safe. Do not expose instances of this type to safe code!
This is a #[repr(transparent)] wrapper around T, so it has the same memory layout as T.
Transmuting between this type and T is valid, but you must uphold the safety requirements for UnsafeSendSync::new.
Implementations§
Source§impl<T> UnsafeSendSync<T>
impl<T> UnsafeSendSync<T>
Sourcepub const unsafe fn new(value: T) -> Self
pub const unsafe fn new(value: T) -> Self
Creates a new UnsafeSendSync<T> wrapping the given value.
§Safety
Creating UnsafeSendSync<T> requires unsafe for construction only.
The caller must ensure that every use of the resulting value is thread-safe; later uses are
not marked unsafe. Do not expose instances of this type to safe code!
Sourcepub const fn safe_new(value: T) -> Self
pub const fn safe_new(value: T) -> Self
A safe alternative to construct UnsafeSendSync<T> when T already implements the required traits.
Sourcepub const fn into_inner(this: Self) -> T
pub const fn into_inner(this: Self) -> T
Consumes the UnsafeSendSync<T> and returns the inner value.
Source§impl<T: ?Sized> UnsafeSendSync<T>
impl<T: ?Sized> UnsafeSendSync<T>
Sourcepub const fn inner_ref(this: &Self) -> &T
pub const fn inner_ref(this: &Self) -> &T
Returns a reference to the inner value of the UnsafeSendSync<T>.
This is a const alternative to dereferencing the wrapper.
Sourcepub const fn inner_mut(this: &mut Self) -> &mut T
pub const fn inner_mut(this: &mut Self) -> &mut T
Returns a mutable reference to the inner value of the UnsafeSendSync<T>.
This is a const alternative to dereferencing the wrapper.
Sourcepub const unsafe fn from_ref(value: &T) -> &Self
pub const unsafe fn from_ref(value: &T) -> &Self
Maps &T to &UnsafeSendSync<T>.
This is useful if you receive a reference to a value that you know will be used in a thread-safe manner.
§Safety
Sourcepub const fn safe_from_ref(value: &T) -> &Self
pub const fn safe_from_ref(value: &T) -> &Self
A safe alternative to UnsafeSendSync<T>::from_ref when T already implements the required traits.
Sourcepub const unsafe fn from_mut(value: &mut T) -> &mut Self
pub const unsafe fn from_mut(value: &mut T) -> &mut Self
Maps &mut T to &mut UnsafeSendSync<T>.
This is useful if you receive a mutable reference to a value that you know will be used in a thread-safe manner.
§Safety
Sourcepub const fn safe_from_mut(value: &mut T) -> &mut Self
pub const fn safe_from_mut(value: &mut T) -> &mut Self
A safe alternative to UnsafeSendSync<T>::from_mut when T already implements the required traits.
Trait Implementations§
Source§impl<T: Clone + ?Sized> Clone for UnsafeSendSync<T>
impl<T: Clone + ?Sized> Clone for UnsafeSendSync<T>
Source§fn clone(&self) -> UnsafeSendSync<T>
fn clone(&self) -> UnsafeSendSync<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<T: ?Sized> Deref for UnsafeSendSync<T>
impl<T: ?Sized> Deref for UnsafeSendSync<T>
Source§impl<T: ?Sized> DerefMut for UnsafeSendSync<T>
impl<T: ?Sized> DerefMut for UnsafeSendSync<T>
Source§impl<T: Ord + ?Sized> Ord for UnsafeSendSync<T>
impl<T: Ord + ?Sized> Ord for UnsafeSendSync<T>
Source§fn cmp(&self, other: &UnsafeSendSync<T>) -> Ordering
fn cmp(&self, other: &UnsafeSendSync<T>) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<T: PartialOrd + ?Sized> PartialOrd for UnsafeSendSync<T>
impl<T: PartialOrd + ?Sized> PartialOrd for UnsafeSendSync<T>
impl<T: Copy + ?Sized> Copy for UnsafeSendSync<T>
impl<T: Eq + ?Sized> Eq for UnsafeSendSync<T>
impl<T: ?Sized> Send for UnsafeSendSync<T>
The wrapper forces the unsafe implementation for T.
impl<T: ?Sized> StructuralPartialEq for UnsafeSendSync<T>
impl<T: ?Sized> Sync for UnsafeSendSync<T>
The wrapper forces the unsafe implementation for T.