pub struct UnsafeSend<T: ?Sized>(/* private fields */);Expand description
A wrapper that unsafely makes T Send 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 UnsafeSend::new.
Implementations§
Source§impl<T> UnsafeSend<T>
impl<T> UnsafeSend<T>
Sourcepub const unsafe fn new(value: T) -> Self
pub const unsafe fn new(value: T) -> Self
Creates a new UnsafeSend<T> wrapping the given value.
§Safety
Creating UnsafeSend<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) -> Selfwhere
T: Send,
pub const fn safe_new(value: T) -> Selfwhere
T: Send,
A safe alternative to construct UnsafeSend<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 UnsafeSend<T> and returns the inner value.
Source§impl<T: ?Sized> UnsafeSend<T>
impl<T: ?Sized> UnsafeSend<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 UnsafeSend<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 UnsafeSend<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 &UnsafeSend<T>.
This is useful if you receive a reference to a value that you know will be used in a thread-safe manner.
§Safety
See UnsafeSend<T>::new.
Sourcepub const fn safe_from_ref(value: &T) -> &Selfwhere
T: Send,
pub const fn safe_from_ref(value: &T) -> &Selfwhere
T: Send,
A safe alternative to UnsafeSend<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 UnsafeSend<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
See UnsafeSend<T>::new.
Sourcepub const fn safe_from_mut(value: &mut T) -> &mut Selfwhere
T: Send,
pub const fn safe_from_mut(value: &mut T) -> &mut Selfwhere
T: Send,
A safe alternative to UnsafeSend<T>::from_mut when T already implements the required traits.
Trait Implementations§
Source§impl<T: Clone + ?Sized> Clone for UnsafeSend<T>
impl<T: Clone + ?Sized> Clone for UnsafeSend<T>
Source§fn clone(&self) -> UnsafeSend<T>
fn clone(&self) -> UnsafeSend<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 UnsafeSend<T>
impl<T: ?Sized> Deref for UnsafeSend<T>
Source§impl<T: ?Sized> DerefMut for UnsafeSend<T>
impl<T: ?Sized> DerefMut for UnsafeSend<T>
Source§impl<T: Ord + ?Sized> Ord for UnsafeSend<T>
impl<T: Ord + ?Sized> Ord for UnsafeSend<T>
Source§fn cmp(&self, other: &UnsafeSend<T>) -> Ordering
fn cmp(&self, other: &UnsafeSend<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 UnsafeSend<T>
impl<T: PartialOrd + ?Sized> PartialOrd for UnsafeSend<T>
impl<T: Copy + ?Sized> Copy for UnsafeSend<T>
impl<T: Eq + ?Sized> Eq for UnsafeSend<T>
impl<T: ?Sized> Send for UnsafeSend<T>
The wrapper forces the unsafe implementation for T.