pub struct SyncWrapper<T>(/* private fields */);Expand description
A wrapper around a non-Sync type to make it Sync.
The mechanism is very simple. SyncWrapper prevents
shared borrowing of the inner type. The only way to get
to the inner data is through take or get_mut. Both methods
can only be called with a mutable reference to SyncWrapper,
so it’s not possible that the inner value can be observed
simultaneously in multiple threads.
Implementations§
Source§impl<T> SyncWrapper<T>
impl<T> SyncWrapper<T>
Trait Implementations§
Source§impl<T: Debug> Debug for SyncWrapper<T>
impl<T: Debug> Debug for SyncWrapper<T>
impl<T: Send> Sync for SyncWrapper<T>
§Safety
SyncWrapper prevents
shared borrowing of the inner type. The only way to get
to the inner data is through take or get_mut. Both methods
can only be called with a mutable reference to SyncWrapper,
so it’s not possible that the inner value can be observed
simultaneously in multiple threads.
Therefore, this implementation is safe.
For further reference, see the standard library’s
implementation of Sync on core::sync::Mutex,
as well as the get_mut method.
Auto Trait Implementations§
impl<T> Freeze for SyncWrapper<T>where
T: Freeze,
impl<T> RefUnwindSafe for SyncWrapper<T>where
T: RefUnwindSafe,
impl<T> Send for SyncWrapper<T>where
T: Send,
impl<T> Unpin for SyncWrapper<T>where
T: Unpin,
impl<T> UnwindSafe for SyncWrapper<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.