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 core::cell::{Cell, UnsafeCell};
use rkyv::{with::Unsafe, Archive};
#[derive(Archive)]
struct Example {
#[rkyv(with = Unsafe)]
cell: Cell<String>,
#[rkyv(with = Unsafe)]
unsafe_cell: UnsafeCell<String>,
}Trait Implementations§
Source§impl<F: Archive> ArchiveWith<UnsafeCell<F>> for Unsafe
impl<F: Archive> ArchiveWith<UnsafeCell<F>> for Unsafe
Source§fn resolve_with(
field: &UnsafeCell<F>,
resolver: Self::Resolver,
out: Place<Self::Archived>,
)
fn resolve_with( field: &UnsafeCell<F>, resolver: Self::Resolver, out: Place<Self::Archived>, )
Resolves the archived type using a reference to the field type
F.Source§impl<F, D> DeserializeWith<<F as Archive>::Archived, UnsafeCell<F>, D> for Unsafe
impl<F, D> DeserializeWith<<F as Archive>::Archived, UnsafeCell<F>, D> for Unsafe
Source§fn deserialize_with(
field: &F::Archived,
deserializer: &mut D,
) -> Result<UnsafeCell<F>, D::Error>
fn deserialize_with( field: &F::Archived, deserializer: &mut D, ) -> Result<UnsafeCell<F>, D::Error>
Deserializes the field type
F using the given deserializer.Source§impl<F, S> SerializeWith<Cell<F>, S> for Unsafe
impl<F, S> SerializeWith<Cell<F>, S> for Unsafe
Source§impl<F, S> SerializeWith<UnsafeCell<F>, S> for Unsafe
impl<F, S> SerializeWith<UnsafeCell<F>, S> for Unsafe
Source§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 Freeze for Unsafe
impl RefUnwindSafe for Unsafe
impl Send for Unsafe
impl Sync for Unsafe
impl Unpin for Unsafe
impl UnsafeUnpin for Unsafe
impl UnwindSafe for Unsafe
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
The archived version of the pointer metadata for this type.
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Converts some archived metadata to the pointer metadata for itself.
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Returns the layout of the type.
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Returns whether the given value has been niched. Read more
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
Writes data to
out indicating that a T is niched.