Struct rkyv::with::Niche

source ·
pub struct Niche;
Expand description

A wrapper that niches some type combinations.

A common type combination is Option<Box<T>>. By using a null pointer, the archived version can save some space on-disk.

Example

use core::mem::size_of;
use rkyv::{Archive, Archived, with::Niche};

#[derive(Archive)]
struct BasicExample {
    value: Option<Box<str>>,
}

#[derive(Archive)]
struct NichedExample {
    #[with(Niche)]
    value: Option<Box<str>>,
}

assert!(size_of::<Archived<BasicExample>>() > size_of::<Archived<NichedExample>>());

Trait Implementations§

source§

impl<T: ArchiveUnsized + ?Sized> ArchiveWith<Option<Box<T, Global>>> for Nichewhere ArchivedMetadata<T>: Default,

§

type Archived = ArchivedOptionBox<<T as ArchiveUnsized>::Archived>

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

type Resolver = OptionBoxResolver<<T as ArchiveUnsized>::MetadataResolver>

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

unsafe fn resolve_with( field: &Option<Box<T>>, 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 ArchiveWith<Option<NonZeroI128>> for Niche

§

type Archived = ArchivedOptionNonZeroI128

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

type Resolver = ()

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

unsafe fn resolve_with( field: &Option<NonZeroI128>, _: usize, _: Self::Resolver, out: *mut Self::Archived )

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

impl ArchiveWith<Option<NonZeroI16>> for Niche

§

type Archived = ArchivedOptionNonZeroI16

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

type Resolver = ()

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

unsafe fn resolve_with( field: &Option<NonZeroI16>, _: usize, _: Self::Resolver, out: *mut Self::Archived )

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

impl ArchiveWith<Option<NonZeroI32>> for Niche

§

type Archived = ArchivedOptionNonZeroI32

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

type Resolver = ()

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

unsafe fn resolve_with( field: &Option<NonZeroI32>, _: usize, _: Self::Resolver, out: *mut Self::Archived )

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

impl ArchiveWith<Option<NonZeroI64>> for Niche

§

type Archived = ArchivedOptionNonZeroI64

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

type Resolver = ()

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

unsafe fn resolve_with( field: &Option<NonZeroI64>, _: usize, _: Self::Resolver, out: *mut Self::Archived )

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

impl ArchiveWith<Option<NonZeroI8>> for Niche

§

type Archived = ArchivedOptionNonZeroI8

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

type Resolver = ()

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

unsafe fn resolve_with( field: &Option<NonZeroI8>, _: usize, _: Self::Resolver, out: *mut Self::Archived )

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

impl ArchiveWith<Option<NonZeroIsize>> for Niche

§

type Archived = ArchivedOptionNonZeroI32

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

type Resolver = ()

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

unsafe fn resolve_with( field: &Option<NonZeroIsize>, _: usize, _: Self::Resolver, out: *mut Self::Archived )

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

impl ArchiveWith<Option<NonZeroU128>> for Niche

§

type Archived = ArchivedOptionNonZeroU128

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

type Resolver = ()

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

unsafe fn resolve_with( field: &Option<NonZeroU128>, _: usize, _: Self::Resolver, out: *mut Self::Archived )

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

impl ArchiveWith<Option<NonZeroU16>> for Niche

§

type Archived = ArchivedOptionNonZeroU16

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

type Resolver = ()

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

unsafe fn resolve_with( field: &Option<NonZeroU16>, _: usize, _: Self::Resolver, out: *mut Self::Archived )

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

impl ArchiveWith<Option<NonZeroU32>> for Niche

§

type Archived = ArchivedOptionNonZeroU32

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

type Resolver = ()

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

unsafe fn resolve_with( field: &Option<NonZeroU32>, _: usize, _: Self::Resolver, out: *mut Self::Archived )

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

impl ArchiveWith<Option<NonZeroU64>> for Niche

§

type Archived = ArchivedOptionNonZeroU64

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

type Resolver = ()

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

unsafe fn resolve_with( field: &Option<NonZeroU64>, _: usize, _: Self::Resolver, out: *mut Self::Archived )

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

impl ArchiveWith<Option<NonZeroU8>> for Niche

§

type Archived = ArchivedOptionNonZeroU8

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

type Resolver = ()

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

unsafe fn resolve_with( field: &Option<NonZeroU8>, _: usize, _: Self::Resolver, out: *mut Self::Archived )

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

impl ArchiveWith<Option<NonZeroUsize>> for Niche

§

type Archived = ArchivedOptionNonZeroU32

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

type Resolver = ()

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

unsafe fn resolve_with( field: &Option<NonZeroUsize>, _: usize, _: Self::Resolver, out: *mut Self::Archived )

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

impl Debug for Niche

source§

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

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

impl<T, D> DeserializeWith<ArchivedOptionBox<<T as ArchiveUnsized>::Archived>, Option<Box<T, Global>>, D> for Nichewhere T: ArchiveUnsized + ?Sized, T::Archived: DeserializeUnsized<T, D>, D: Fallible + ?Sized,

source§

fn deserialize_with( field: &ArchivedOptionBox<T::Archived>, deserializer: &mut D ) -> Result<Option<Box<T>>, D::Error>

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

impl<D: Fallible + ?Sized> DeserializeWith<ArchivedOptionNonZeroI128, Option<NonZeroI128>, D> for Niche

source§

fn deserialize_with( field: &ArchivedOptionNonZeroI128, _: &mut D ) -> Result<Option<NonZeroI128>, D::Error>

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

impl<D: Fallible + ?Sized> DeserializeWith<ArchivedOptionNonZeroI16, Option<NonZeroI16>, D> for Niche

source§

fn deserialize_with( field: &ArchivedOptionNonZeroI16, _: &mut D ) -> Result<Option<NonZeroI16>, D::Error>

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

impl<D: Fallible + ?Sized> DeserializeWith<ArchivedOptionNonZeroI32, Option<NonZeroI32>, D> for Niche

source§

fn deserialize_with( field: &ArchivedOptionNonZeroI32, _: &mut D ) -> Result<Option<NonZeroI32>, D::Error>

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

impl<D: Fallible + ?Sized> DeserializeWith<ArchivedOptionNonZeroI32, Option<NonZeroIsize>, D> for Niche

source§

fn deserialize_with( field: &ArchivedOptionNonZeroI32, _: &mut D ) -> Result<Option<NonZeroIsize>, D::Error>

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

impl<D: Fallible + ?Sized> DeserializeWith<ArchivedOptionNonZeroI64, Option<NonZeroI64>, D> for Niche

source§

fn deserialize_with( field: &ArchivedOptionNonZeroI64, _: &mut D ) -> Result<Option<NonZeroI64>, D::Error>

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

impl<D: Fallible + ?Sized> DeserializeWith<ArchivedOptionNonZeroI8, Option<NonZeroI8>, D> for Niche

source§

fn deserialize_with( field: &ArchivedOptionNonZeroI8, _: &mut D ) -> Result<Option<NonZeroI8>, D::Error>

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

impl<D: Fallible + ?Sized> DeserializeWith<ArchivedOptionNonZeroU128, Option<NonZeroU128>, D> for Niche

source§

fn deserialize_with( field: &ArchivedOptionNonZeroU128, _: &mut D ) -> Result<Option<NonZeroU128>, D::Error>

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

impl<D: Fallible + ?Sized> DeserializeWith<ArchivedOptionNonZeroU16, Option<NonZeroU16>, D> for Niche

source§

fn deserialize_with( field: &ArchivedOptionNonZeroU16, _: &mut D ) -> Result<Option<NonZeroU16>, D::Error>

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

impl<D: Fallible + ?Sized> DeserializeWith<ArchivedOptionNonZeroU32, Option<NonZeroU32>, D> for Niche

source§

fn deserialize_with( field: &ArchivedOptionNonZeroU32, _: &mut D ) -> Result<Option<NonZeroU32>, D::Error>

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

impl<D: Fallible + ?Sized> DeserializeWith<ArchivedOptionNonZeroU32, Option<NonZeroUsize>, D> for Niche

source§

fn deserialize_with( field: &ArchivedOptionNonZeroU32, _: &mut D ) -> Result<Option<NonZeroUsize>, D::Error>

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

impl<D: Fallible + ?Sized> DeserializeWith<ArchivedOptionNonZeroU64, Option<NonZeroU64>, D> for Niche

source§

fn deserialize_with( field: &ArchivedOptionNonZeroU64, _: &mut D ) -> Result<Option<NonZeroU64>, D::Error>

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

impl<D: Fallible + ?Sized> DeserializeWith<ArchivedOptionNonZeroU8, Option<NonZeroU8>, D> for Niche

source§

fn deserialize_with( field: &ArchivedOptionNonZeroU8, _: &mut D ) -> Result<Option<NonZeroU8>, D::Error>

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

impl<T, S> SerializeWith<Option<Box<T, Global>>, S> for Nichewhere T: SerializeUnsized<S> + ?Sized, S: Serializer + ?Sized, ArchivedMetadata<T>: Default,

source§

fn serialize_with( field: &Option<Box<T>>, serializer: &mut S ) -> Result<Self::Resolver, S::Error>

Serializes the field type F using the given serializer.
source§

impl<S: Fallible + ?Sized> SerializeWith<Option<NonZeroI128>, S> for Niche

source§

fn serialize_with( _: &Option<NonZeroI128>, _: &mut S ) -> Result<Self::Resolver, S::Error>

Serializes the field type F using the given serializer.
source§

impl<S: Fallible + ?Sized> SerializeWith<Option<NonZeroI16>, S> for Niche

source§

fn serialize_with( _: &Option<NonZeroI16>, _: &mut S ) -> Result<Self::Resolver, S::Error>

Serializes the field type F using the given serializer.
source§

impl<S: Fallible + ?Sized> SerializeWith<Option<NonZeroI32>, S> for Niche

source§

fn serialize_with( _: &Option<NonZeroI32>, _: &mut S ) -> Result<Self::Resolver, S::Error>

Serializes the field type F using the given serializer.
source§

impl<S: Fallible + ?Sized> SerializeWith<Option<NonZeroI64>, S> for Niche

source§

fn serialize_with( _: &Option<NonZeroI64>, _: &mut S ) -> Result<Self::Resolver, S::Error>

Serializes the field type F using the given serializer.
source§

impl<S: Fallible + ?Sized> SerializeWith<Option<NonZeroI8>, S> for Niche

source§

fn serialize_with( _: &Option<NonZeroI8>, _: &mut S ) -> Result<Self::Resolver, S::Error>

Serializes the field type F using the given serializer.
source§

impl<S: Fallible + ?Sized> SerializeWith<Option<NonZeroIsize>, S> for Niche

source§

fn serialize_with( _: &Option<NonZeroIsize>, _: &mut S ) -> Result<Self::Resolver, S::Error>

Serializes the field type F using the given serializer.
source§

impl<S: Fallible + ?Sized> SerializeWith<Option<NonZeroU128>, S> for Niche

source§

fn serialize_with( _: &Option<NonZeroU128>, _: &mut S ) -> Result<Self::Resolver, S::Error>

Serializes the field type F using the given serializer.
source§

impl<S: Fallible + ?Sized> SerializeWith<Option<NonZeroU16>, S> for Niche

source§

fn serialize_with( _: &Option<NonZeroU16>, _: &mut S ) -> Result<Self::Resolver, S::Error>

Serializes the field type F using the given serializer.
source§

impl<S: Fallible + ?Sized> SerializeWith<Option<NonZeroU32>, S> for Niche

source§

fn serialize_with( _: &Option<NonZeroU32>, _: &mut S ) -> Result<Self::Resolver, S::Error>

Serializes the field type F using the given serializer.
source§

impl<S: Fallible + ?Sized> SerializeWith<Option<NonZeroU64>, S> for Niche

source§

fn serialize_with( _: &Option<NonZeroU64>, _: &mut S ) -> Result<Self::Resolver, S::Error>

Serializes the field type F using the given serializer.
source§

impl<S: Fallible + ?Sized> SerializeWith<Option<NonZeroU8>, S> for Niche

source§

fn serialize_with( _: &Option<NonZeroU8>, _: &mut S ) -> Result<Self::Resolver, S::Error>

Serializes the field type F using the given serializer.
source§

impl<S: Fallible + ?Sized> SerializeWith<Option<NonZeroUsize>, S> for Niche

source§

fn serialize_with( _: &Option<NonZeroUsize>, _: &mut S ) -> Result<Self::Resolver, S::Error>

Serializes the field type F using the given serializer.

Auto Trait Implementations§

§

impl RefUnwindSafe for Niche

§

impl Send for Niche

§

impl Sync for Niche

§

impl Unpin for Niche

§

impl UnwindSafe for Niche

Blanket Implementations§

source§

impl<T> Any for Twhere 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> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · 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 Fwhere 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

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.