pub struct Lock;
Expand description
A wrapper that locks a lock and serializes the value immutably.
This wrapper can panic under very specific circumstances when:
serialize_with
is called and succeeds in locking the value to serialize it.- Another thread locks the value and panics, poisoning the lock
resolve_with
is called and gets a poisoned value.
Unfortunately, it’s not possible to work around this issue. If your code absolutely must not panic under any circumstances, it’s recommended that you lock your values and then serialize them while locked.
Regular serializers don’t support the custom error handling needed for this type by default. To
use this wrapper, a custom serializer with an error type satisfying
<S as Fallible>::Error: From<LockError>
must be provided.
Example
use std::sync::Mutex;
use rkyv::{Archive, with::Lock};
#[derive(Archive)]
struct Example {
#[with(Lock)]
a: Mutex<i32>,
}
Trait Implementations
sourceimpl<F: Archive> ArchiveWith<Mutex<F>> for Lock
impl<F: Archive> ArchiveWith<Mutex<F>> for Lock
sourceimpl<F: Archive> ArchiveWith<RwLock<F>> for Lock
impl<F: Archive> ArchiveWith<RwLock<F>> for Lock
sourceimpl<F, T, D> DeserializeWith<Immutable<F>, Mutex<T>, D> for Lock where
F: Deserialize<T, D>,
D: Fallible + ?Sized,
impl<F, T, D> DeserializeWith<Immutable<F>, Mutex<T>, D> for Lock where
F: Deserialize<T, D>,
D: Fallible + ?Sized,
sourceimpl<F, T, D> DeserializeWith<Immutable<F>, RwLock<T>, D> for Lock where
F: Deserialize<T, D>,
D: Fallible + ?Sized,
impl<F, T, D> DeserializeWith<Immutable<F>, RwLock<T>, D> for Lock where
F: Deserialize<T, D>,
D: Fallible + ?Sized,
Auto Trait Implementations
impl RefUnwindSafe for Lock
impl Send for Lock
impl Sync for Lock
impl Unpin for Lock
impl UnwindSafe for Lock
Blanket Implementations
sourceimpl<T> ArchivePointee for T
impl<T> ArchivePointee for T
type ArchivedMetadata = ()
type ArchivedMetadata = ()
The archived version of the pointer metadata for this type.
sourcefn pointer_metadata(_: &Self::ArchivedMetadata) -> <Self as Pointee>::Metadata
fn pointer_metadata(_: &Self::ArchivedMetadata) -> <Self as Pointee>::Metadata
Converts some archived metadata to the pointer metadata for itself.
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more