pub struct Unsafe;
Expand description
A wrapper that allows serialize-unsafe types to be serialized.
Types like Cell
and UnsafeCell
may contain serializable types, but have unsafe access
semantics due to interior mutability. They may be safe to serialize, but only under conditions
that rkyv is unable to guarantee.
This wrapper enables serializing these types, and places the burden of verifying that their access semantics are used safely on the user.
Safety
Using this wrapper on types with interior mutability can create races conditions or allow access to data in an invalid state if access semantics are not followed properly. During serialization, the data must not be modified.
Example
use rkyv::{Archive, with::Unsafe};
use core::cell::{Cell, UnsafeCell};
#[derive(Archive)]
struct Example {
#[with(Unsafe)]
cell: Cell<String>,
#[with(Unsafe)]
unsafe_cell: UnsafeCell<String>,
}
Trait Implementations
sourceimpl<F: Archive> ArchiveWith<Cell<F>> for Unsafe
impl<F: Archive> ArchiveWith<Cell<F>> for Unsafe
sourceimpl<F: Archive> ArchiveWith<UnsafeCell<F>> for Unsafe
impl<F: Archive> ArchiveWith<UnsafeCell<F>> for Unsafe
type Archived = UnsafeCell<F::Archived>
type Archived = UnsafeCell<F::Archived>
The archived type of a With<F, Self>
.
sourceunsafe fn resolve_with(
field: &UnsafeCell<F>,
pos: usize,
resolver: Self::Resolver,
out: *mut Self::Archived
)
unsafe fn resolve_with(
field: &UnsafeCell<F>,
pos: usize,
resolver: Self::Resolver,
out: *mut Self::Archived
)
Resolves the archived type using a reference to the field type F
. Read more
sourceimpl<F: Archive, D: Fallible + ?Sized> DeserializeWith<Cell<<F as Archive>::Archived>, Cell<F>, D> for Unsafe where
F::Archived: Deserialize<F, D>,
impl<F: Archive, D: Fallible + ?Sized> DeserializeWith<Cell<<F as Archive>::Archived>, Cell<F>, D> for Unsafe where
F::Archived: Deserialize<F, D>,
sourceimpl<F: Archive, D: Fallible + ?Sized> DeserializeWith<UnsafeCell<<F as Archive>::Archived>, UnsafeCell<F>, D> for Unsafe where
F::Archived: Deserialize<F, D>,
impl<F: Archive, D: Fallible + ?Sized> DeserializeWith<UnsafeCell<<F as Archive>::Archived>, UnsafeCell<F>, D> for Unsafe where
F::Archived: Deserialize<F, D>,
sourcefn deserialize_with(
field: &UnsafeCell<F::Archived>,
deserializer: &mut D
) -> Result<UnsafeCell<F>, D::Error>
fn deserialize_with(
field: &UnsafeCell<F::Archived>,
deserializer: &mut D
) -> Result<UnsafeCell<F>, D::Error>
Deserializes the field type F
using the given deserializer.
sourceimpl<F: Serialize<S>, S: Fallible + ?Sized> SerializeWith<UnsafeCell<F>, S> for Unsafe
impl<F: Serialize<S>, S: Fallible + ?Sized> SerializeWith<UnsafeCell<F>, S> for Unsafe
sourcefn serialize_with(
field: &UnsafeCell<F>,
serializer: &mut S
) -> Result<Self::Resolver, S::Error>
fn serialize_with(
field: &UnsafeCell<F>,
serializer: &mut S
) -> Result<Self::Resolver, S::Error>
Serializes the field type F
using the given serializer.
Auto Trait Implementations
impl RefUnwindSafe for Unsafe
impl Send for Unsafe
impl Sync for Unsafe
impl Unpin for Unsafe
impl UnwindSafe for Unsafe
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