Struct rkyv::with::Unsafe [−][src]
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
type Archived = UnsafeCell<F::Archived>
type Archived = UnsafeCell<F::Archived>
The archived type of a With<F, Self>.
unsafe 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
impl<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>,
fn 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.
fn 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 UnwindSafe for Unsafe
Blanket Implementations
type ArchivedMetadata = ()
type ArchivedMetadata = ()
The archived version of the pointer metadata for this type.
Converts some archived metadata to the pointer metadata for itself.
Mutably borrows from an owned value. Read more