pub struct UnsafeLock<T: ?Sized> { /* private fields */ }Implementations§
Source§impl<T> UnsafeLock<T>
impl<T> UnsafeLock<T>
Sourcepub unsafe fn new(value: T) -> Self
pub unsafe fn new(value: T) -> Self
§Safety
There must be no copies of the value. See Send implementation.
Trait Implementations§
Source§impl<T: Clone + ?Sized> Clone for UnsafeLock<T>
impl<T: Clone + ?Sized> Clone for UnsafeLock<T>
Source§fn clone(&self) -> UnsafeLock<T>
fn clone(&self) -> UnsafeLock<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<T: Debug> Debug for UnsafeLock<T>
impl<T: Debug> Debug for UnsafeLock<T>
impl<T: ?Sized> Send for UnsafeLock<T>
Unlike Mutex, this lock is Send and Sync regardless of whether T is Send or not.
That’s because T is always under the protection of this lock whenever clients uphold the
safety of the lock.
§Safety
There must be no copies of the value inside this lock. Clients must not have copies before
and after creation of this lock. Because this lock assumes that the value inside the lock
has no copies, so the lock is Send and Sync even if T isn’t.
For example, imagine that you have multiple Rc<T>, which is not Send, and make
UnsafeLock<Rc<T>> from one copy of them, then you send the lock to another thread. It can
cause data race because of Rc<T> outside this lock.
But if you have only one T and wrap it within UnsafeLock, then T is guaranteed to be
protected by this lock. Making copies of UnsafeLock<T>, sending it to another thread, and
accessing it from another thread does not break the guarantee. But you still can make copies
of T from its pointer, but you shouldn’t.