pub struct SendWrapper<T> { /* private fields */ }Expand description
A wrapper which allows you to move around non-Send-types between
threads, as long as you access the contained value only from within the
original thread and make sure that it is dropped from within the original
thread.
Implementations§
Source§impl<T> SendWrapper<T>
impl<T> SendWrapper<T>
Sourcepub fn new(data: T) -> SendWrapper<T> ⓘ
pub fn new(data: T) -> SendWrapper<T> ⓘ
Create a SendWrapper<T> wrapper around a value of type T.
The wrapper takes ownership of the value.
Sourcepub fn valid(&self) -> bool
pub fn valid(&self) -> bool
Returns true if the value can be safely accessed from within the
current thread.
Sourcepub unsafe fn take_unchecked(self) -> T
pub unsafe fn take_unchecked(self) -> T
Takes the value out of the SendWrapper<T>.
§Safety
The caller should be in the same thread as the creator.
Sourcepub fn take(self) -> T
pub fn take(self) -> T
Takes the value out of the SendWrapper<T>.
§Panics
Panics if it is called from a different thread than the one the
SendWrapper<T> instance has been created with.
Sourcepub unsafe fn get_unchecked(&self) -> &T
pub unsafe fn get_unchecked(&self) -> &T
Returns a reference to the contained value.
§Safety
The caller should be in the same thread as the creator.
Sourcepub unsafe fn get_unchecked_mut(&mut self) -> &mut T
pub unsafe fn get_unchecked_mut(&mut self) -> &mut T
Returns a mutable reference to the contained value.
§Safety
The caller should be in the same thread as the creator.
Sourcepub unsafe fn get_unchecked_pinned(self: Pin<&Self>) -> Pin<&T>
pub unsafe fn get_unchecked_pinned(self: Pin<&Self>) -> Pin<&T>
Returns a pinned reference to the contained value.
§Safety
The caller should be in the same thread as the creator.
Sourcepub unsafe fn get_unchecked_pinned_mut(self: Pin<&mut Self>) -> Pin<&mut T>
pub unsafe fn get_unchecked_pinned_mut(self: Pin<&mut Self>) -> Pin<&mut T>
Returns a pinned mutable reference to the contained value.
§Safety
The caller should be in the same thread as the creator.
Sourcepub fn get_mut(&mut self) -> Option<&mut T>
pub fn get_mut(&mut self) -> Option<&mut T>
Returns a mutable reference to the contained value, if valid.
Sourcepub fn get_pinned(self: Pin<&Self>) -> Option<Pin<&T>>
pub fn get_pinned(self: Pin<&Self>) -> Option<Pin<&T>>
Returns a pinned reference to the contained value, if valid.
Sourcepub fn get_pinned_mut(self: Pin<&mut Self>) -> Option<Pin<&mut T>>
pub fn get_pinned_mut(self: Pin<&mut Self>) -> Option<Pin<&mut T>>
Returns a pinned mutable reference to the contained value, if valid.
Sourcepub fn tracker(&self) -> SendWrapper<()> ⓘ
pub fn tracker(&self) -> SendWrapper<()> ⓘ
Returns a tracker that can be used to check if the current thread is the same as the creator thread.
Trait Implementations§
Source§impl<T: Clone> Clone for SendWrapper<T>
impl<T: Clone> Clone for SendWrapper<T>
Source§impl<T: Debug> Debug for SendWrapper<T>
impl<T: Debug> Debug for SendWrapper<T>
Source§impl<T> Drop for SendWrapper<T>
impl<T> Drop for SendWrapper<T>
Source§fn drop(&mut self)
fn drop(&mut self)
Drops the contained value.
§Panics
Dropping panics if it is done from a different thread than the one the
SendWrapper<T> instance has been created with.
Exceptions:
- There is no extra panic if the thread is already panicking/unwinding. This is because otherwise there would be double panics (usually resulting in an abort) when dereferencing from a wrong thread.
- If
Thas a trivial drop (needs_drop::<T>()is false) then this method never panics.
Source§impl<F: Future> Future for SendWrapper<F>
Available on crate feature futures only.
impl<F: Future> Future for SendWrapper<F>
futures only.Source§impl<S: Stream> Stream for SendWrapper<S>
Available on crate feature futures only.
impl<S: Stream> Stream for SendWrapper<S>
futures only.