Struct rkyv::with::With

source ·
pub struct With<F: ?Sized, W> { /* private fields */ }
Expand description

A transparent wrapper for archived fields.

This is used by the #[with(...)] attribute in the Archive macro to create transparent serialization wrappers. Those wrappers leverage ArchiveWith to change how the type is archived, serialized, and deserialized.

When a field is serialized, a reference to the field (i.e. &T) can be cast to a reference to a wrapping With (i.e. With<T, Wrapper>) and serialized instead. This is safe to do because With is a transparent wrapper and is shaped exactly the same as the underlying field.

§Example

use rkyv::{Archive, with::Inline};

#[derive(Archive)]
struct Example<'a> {
    // This will archive as if it were With<&'a i32, Inline>. That will delegate the archival
    // to the ArchiveWith implementation of Inline for &T.
    #[with(Inline)]
    a: &'a i32,
}

Implementations§

source§

impl<F: ?Sized, W> With<F, W>

source

pub fn cast(field: &F) -> &With<F, W>

Casts a With reference from a reference to the underlying field.

This is always safe to do because With is a transparent wrapper.

source§

impl<F, W> With<F, W>

source

pub fn into_inner(self) -> F

Unwraps a With into the underlying field.

Trait Implementations§

source§

impl<F: ?Sized, W: ArchiveWith<F>> Archive for With<F, W>

§

type Archived = <W as ArchiveWith<F>>::Archived

The archived representation of this type. Read more
§

type Resolver = <W as ArchiveWith<F>>::Resolver

The resolver for this type. It must contain all the additional information from serializing needed to make the archived type from the normal type.
source§

unsafe fn resolve( &self, pos: usize, resolver: Self::Resolver, out: *mut Self::Archived )

Creates the archived version of this value at the given position and writes it to the given output. Read more
source§

impl<'a, T: Archive> ArchiveWith<With<&'a [T], RefAsBox>> for CopyOptimize

§

type Archived = ArchivedBox<[<T as Archive>::Archived]>

The archived type of a With<F, Self>.
§

type Resolver = BoxResolver<<[T] as ArchiveUnsized>::MetadataResolver>

The resolver of a With<F, Self>.
source§

unsafe fn resolve_with( field: &With<&'a [T], RefAsBox>, pos: usize, resolver: Self::Resolver, out: *mut Self::Archived )

Resolves the archived type using a reference to the field type F. Read more
source§

impl<F: ?Sized, W> AsRef<F> for With<F, W>

source§

fn as_ref(&self) -> &F

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

impl<F: Debug + ?Sized, W: Debug> Debug for With<F, W>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<D: Fallible + ?Sized> DeserializeWith<<With<AtomicI16, Atomic> as Archive>::Archived, AtomicI16, D> for Atomic

source§

fn deserialize_with( field: &Archived<With<AtomicI16, Self>>, _: &mut D ) -> Result<AtomicI16, D::Error>

Deserializes the field type F using the given deserializer.
source§

impl<D: Fallible + ?Sized> DeserializeWith<<With<AtomicI32, Atomic> as Archive>::Archived, AtomicI32, D> for Atomic

source§

fn deserialize_with( field: &Archived<With<AtomicI32, Self>>, _: &mut D ) -> Result<AtomicI32, D::Error>

Deserializes the field type F using the given deserializer.
source§

impl<D: Fallible + ?Sized> DeserializeWith<<With<AtomicI64, Atomic> as Archive>::Archived, AtomicI64, D> for Atomic

source§

fn deserialize_with( field: &Archived<With<AtomicI64, Self>>, _: &mut D ) -> Result<AtomicI64, D::Error>

Deserializes the field type F using the given deserializer.
source§

impl<D: Fallible + ?Sized> DeserializeWith<<With<AtomicIsize, Atomic> as Archive>::Archived, AtomicIsize, D> for Atomic

source§

fn deserialize_with( field: &Archived<With<AtomicIsize, Self>>, _: &mut D ) -> Result<AtomicIsize, D::Error>

Deserializes the field type F using the given deserializer.
source§

impl<D: Fallible + ?Sized> DeserializeWith<<With<AtomicU16, Atomic> as Archive>::Archived, AtomicU16, D> for Atomic

source§

fn deserialize_with( field: &Archived<With<AtomicU16, Self>>, _: &mut D ) -> Result<AtomicU16, D::Error>

Deserializes the field type F using the given deserializer.
source§

impl<D: Fallible + ?Sized> DeserializeWith<<With<AtomicU32, Atomic> as Archive>::Archived, AtomicU32, D> for Atomic

source§

fn deserialize_with( field: &Archived<With<AtomicU32, Self>>, _: &mut D ) -> Result<AtomicU32, D::Error>

Deserializes the field type F using the given deserializer.
source§

impl<D: Fallible + ?Sized> DeserializeWith<<With<AtomicU64, Atomic> as Archive>::Archived, AtomicU64, D> for Atomic

source§

fn deserialize_with( field: &Archived<With<AtomicU64, Self>>, _: &mut D ) -> Result<AtomicU64, D::Error>

Deserializes the field type F using the given deserializer.
source§

impl<F: ?Sized, W: SerializeWith<F, S>, S: Fallible + ?Sized> Serialize<S> for With<F, W>

source§

fn serialize(&self, serializer: &mut S) -> Result<Self::Resolver, S::Error>

Writes the dependencies for the object and returns a resolver that can create the archived type.
source§

impl<'a, T, S> SerializeWith<With<&'a [T], RefAsBox>, S> for CopyOptimize
where T: Serialize<S>, S: Serializer + ?Sized,

source§

fn serialize_with( field: &With<&'a [T], RefAsBox>, serializer: &mut S ) -> Result<Self::Resolver, S::Error>

Serializes the field type F using the given serializer.

Auto Trait Implementations§

§

impl<F: ?Sized, W> RefUnwindSafe for With<F, W>

§

impl<F: ?Sized, W> Send for With<F, W>
where F: Send, W: Send,

§

impl<F: ?Sized, W> Sync for With<F, W>
where F: Sync, W: Sync,

§

impl<F: ?Sized, W> Unpin for With<F, W>
where F: Unpin, W: Unpin,

§

impl<F: ?Sized, W> UnwindSafe for With<F, W>
where F: UnwindSafe, W: UnwindSafe,

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

§

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> ArchiveUnsized for T
where T: Archive,

§

type Archived = <T as Archive>::Archived

The archived counterpart of this type. Unlike Archive, it may be unsized. Read more
§

type MetadataResolver = ()

The resolver for the metadata of this type. Read more
source§

unsafe fn resolve_metadata( &self, _: usize, _: <T as ArchiveUnsized>::MetadataResolver, _: *mut <<T as ArchiveUnsized>::Archived as ArchivePointee>::ArchivedMetadata )

Creates the archived version of the metadata for this value at the given position and writes it to the given output. Read more
source§

unsafe fn resolve_unsized( &self, from: usize, to: usize, resolver: Self::MetadataResolver, out: *mut RelPtr<Self::Archived> )

Resolves a relative pointer to this value with the given from and to and writes it to the given output. Read more
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<F, W, T, D> Deserialize<With<T, W>, D> for F
where W: DeserializeWith<F, T, D>, D: Fallible + ?Sized, F: ?Sized,

source§

fn deserialize( &self, deserializer: &mut D ) -> Result<With<T, W>, <D as Fallible>::Error>

Deserializes using the given deserializer
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>

Gets the layout of the type.
source§

impl<T> Pointee for T

§

type Metadata = ()

The type for metadata in pointers and references to Self.
source§

impl<T, S> SerializeUnsized<S> for T
where T: Serialize<S>, S: Serializer + ?Sized,

source§

fn serialize_unsized( &self, serializer: &mut S ) -> Result<usize, <S as Fallible>::Error>

Writes the object and returns the position of the archived type.
source§

fn serialize_metadata(&self, _: &mut S) -> Result<(), <S as Fallible>::Error>

Serializes the metadata for the given type.
source§

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

§

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

§

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.