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.
Additionally, mutating the data protected by a mutex between the serialize and resolve steps may cause undefined behavior in the resolve step. Uses of this wrapper should be considered unsafe with the requirement that the data not be mutated between these two steps.
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>,
}