rkyv::seal

Struct Seal

Source
pub struct Seal<'a, T: ?Sized> { /* private fields */ }
Expand description

A mutable reference which may not be moved or assigned.

A Seal restricts a mutable reference so that the referenced value cannot be moved or assigned unless it is Unpin and NoUndef. These properties allow the safe use of mutable archived values.

Unlike Pin, all fields of Sealed values are also sealed. There is no notion of “structural sealing” as there is structural pinning. This has the upside that a Seal can be uniformly destructured with munge, which is the recommended replacement for Pin’s map_unchecked_mut function. Also unlike Pin, Sealing a reference does not require upholding the invariant that the sealed value is dropped before its backing memory is reused. This means that creating a Seal from a mutable reference is completely safe to do.

Implementations§

Source§

impl<'a, T: ?Sized> Seal<'a, T>

Source

pub fn new(inner: &'a mut T) -> Self

Returns a new Seal wrapping the given reference.

Source

pub fn unseal(self) -> &'a mut T
where T: NoUndef + Unpin,

Returns the underlying reference for types that implement NoUndef and Unpin.

Source

pub fn unseal_ref(self) -> &'a T

Returns the underlying reference as shared for types that implement Portable.

Source

pub unsafe fn unseal_unchecked(self) -> &'a mut T

Returns the underlying reference.

§Safety

The returned reference may not be moved unless T is Unpin. Uninitialized bytes may not be written through the Seal.

Source

pub fn as_mut(&mut self) -> Seal<'_, T>

Mutably reborrows the Seal.

Source§

impl<'a, T> Seal<'a, [T]>

Source

pub fn index<I: SliceIndex<[T]>>( self, index: I, ) -> Seal<'a, <I as SliceIndex<[T]>>::Output>

Indexes the Seal.

§Panics

May panic if the index is out of bounds.

Trait Implementations§

Source§

impl<T: ?Sized> AsRef<T> for Seal<'_, T>

Source§

fn as_ref(&self) -> &T

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T: ?Sized> Deref for Seal<'_, T>

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<T: NoUndef + Unpin + ?Sized> DerefMut for Seal<'_, T>

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<T: ?Sized> Destructure for Seal<'_, T>

Source§

type Underlying = T

The underlying type that is destructured.
Source§

type Destructuring = Borrow

The type of destructuring to perform.
Source§

fn underlying(&mut self) -> *mut Self::Underlying

Returns a mutable pointer to the underlying type.
Source§

impl<'a, T> IntoIterator for Seal<'a, ArchivedOption<T>>

Source§

type Item = Seal<'a, T>

The type of the elements being iterated over.
Source§

type IntoIter = Iter<Seal<'a, T>>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a, T: ?Sized, U: 'a + ?Sized> Restructure<U> for Seal<'a, T>

Source§

type Restructured = Seal<'a, U>

The restructured version of this type.
Source§

unsafe fn restructure(&self, ptr: *mut U) -> Self::Restructured

Restructures a pointer to this type into the target type. Read more

Auto Trait Implementations§

§

impl<'a, T> Freeze for Seal<'a, T>
where T: ?Sized,

§

impl<'a, T> RefUnwindSafe for Seal<'a, T>
where T: RefUnwindSafe + ?Sized,

§

impl<'a, T> Send for Seal<'a, T>
where T: Send + ?Sized,

§

impl<'a, T> Sync for Seal<'a, T>
where T: Sync + ?Sized,

§

impl<'a, T> Unpin for Seal<'a, T>
where T: ?Sized,

§

impl<'a, T> !UnwindSafe for Seal<'a, T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> ArchivePointee for T

Source§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
Source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> LayoutRaw for T

Source§

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
where T: SharedNiching<N1, N2>, N1: Niching<T>, N2: Niching<T>,

Source§

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>>)

Writes data to out indicating that a T is niched.
Source§

impl<T> Pointee for T

Source§

type Metadata = ()

The metadata type for pointers and references to this type.
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
Available on non-bootstrap only.
The target type on which the method may be called.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.