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>>> for Nichewhere
ArchivedMetadata<T>: Default,
impl<T: ArchiveUnsized + ?Sized> ArchiveWith<Option<Box<T>>> for Nichewhere
ArchivedMetadata<T>: Default,
§type Archived = ArchivedOptionBox<<T as ArchiveUnsized>::Archived>
type Archived = ArchivedOptionBox<<T as ArchiveUnsized>::Archived>
The archived type of a
With<F, Self>
.§type Resolver = OptionBoxResolver<<T as ArchiveUnsized>::MetadataResolver>
type Resolver = OptionBoxResolver<<T as ArchiveUnsized>::MetadataResolver>
The resolver of a
With<F, Self>
.source§impl ArchiveWith<Option<NonZero<i128>>> for Niche
impl ArchiveWith<Option<NonZero<i128>>> for Niche
§type Archived = ArchivedOptionNonZeroI128
type Archived = ArchivedOptionNonZeroI128
The archived type of a
With<F, Self>
.source§unsafe fn resolve_with(
field: &Option<NonZeroI128>,
_: usize,
_: Self::Resolver,
out: *mut Self::Archived,
)
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 moresource§impl ArchiveWith<Option<NonZero<i16>>> for Niche
impl ArchiveWith<Option<NonZero<i16>>> for Niche
§type Archived = ArchivedOptionNonZeroI16
type Archived = ArchivedOptionNonZeroI16
The archived type of a
With<F, Self>
.source§unsafe fn resolve_with(
field: &Option<NonZeroI16>,
_: usize,
_: Self::Resolver,
out: *mut Self::Archived,
)
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 moresource§impl ArchiveWith<Option<NonZero<i32>>> for Niche
impl ArchiveWith<Option<NonZero<i32>>> for Niche
§type Archived = ArchivedOptionNonZeroI32
type Archived = ArchivedOptionNonZeroI32
The archived type of a
With<F, Self>
.source§unsafe fn resolve_with(
field: &Option<NonZeroI32>,
_: usize,
_: Self::Resolver,
out: *mut Self::Archived,
)
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 moresource§impl ArchiveWith<Option<NonZero<i64>>> for Niche
impl ArchiveWith<Option<NonZero<i64>>> for Niche
§type Archived = ArchivedOptionNonZeroI64
type Archived = ArchivedOptionNonZeroI64
The archived type of a
With<F, Self>
.source§unsafe fn resolve_with(
field: &Option<NonZeroI64>,
_: usize,
_: Self::Resolver,
out: *mut Self::Archived,
)
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 moresource§impl ArchiveWith<Option<NonZero<i8>>> for Niche
impl ArchiveWith<Option<NonZero<i8>>> for Niche
§type Archived = ArchivedOptionNonZeroI8
type Archived = ArchivedOptionNonZeroI8
The archived type of a
With<F, Self>
.source§impl ArchiveWith<Option<NonZero<isize>>> for Niche
impl ArchiveWith<Option<NonZero<isize>>> for Niche
§type Archived = ArchivedOptionNonZeroI32
type Archived = ArchivedOptionNonZeroI32
The archived type of a
With<F, Self>
.source§unsafe fn resolve_with(
field: &Option<NonZeroIsize>,
_: usize,
_: Self::Resolver,
out: *mut Self::Archived,
)
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 moresource§impl ArchiveWith<Option<NonZero<u128>>> for Niche
impl ArchiveWith<Option<NonZero<u128>>> for Niche
§type Archived = ArchivedOptionNonZeroU128
type Archived = ArchivedOptionNonZeroU128
The archived type of a
With<F, Self>
.source§unsafe fn resolve_with(
field: &Option<NonZeroU128>,
_: usize,
_: Self::Resolver,
out: *mut Self::Archived,
)
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 moresource§impl ArchiveWith<Option<NonZero<u16>>> for Niche
impl ArchiveWith<Option<NonZero<u16>>> for Niche
§type Archived = ArchivedOptionNonZeroU16
type Archived = ArchivedOptionNonZeroU16
The archived type of a
With<F, Self>
.source§unsafe fn resolve_with(
field: &Option<NonZeroU16>,
_: usize,
_: Self::Resolver,
out: *mut Self::Archived,
)
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 moresource§impl ArchiveWith<Option<NonZero<u32>>> for Niche
impl ArchiveWith<Option<NonZero<u32>>> for Niche
§type Archived = ArchivedOptionNonZeroU32
type Archived = ArchivedOptionNonZeroU32
The archived type of a
With<F, Self>
.source§unsafe fn resolve_with(
field: &Option<NonZeroU32>,
_: usize,
_: Self::Resolver,
out: *mut Self::Archived,
)
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 moresource§impl ArchiveWith<Option<NonZero<u64>>> for Niche
impl ArchiveWith<Option<NonZero<u64>>> for Niche
§type Archived = ArchivedOptionNonZeroU64
type Archived = ArchivedOptionNonZeroU64
The archived type of a
With<F, Self>
.source§unsafe fn resolve_with(
field: &Option<NonZeroU64>,
_: usize,
_: Self::Resolver,
out: *mut Self::Archived,
)
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 moresource§impl ArchiveWith<Option<NonZero<u8>>> for Niche
impl ArchiveWith<Option<NonZero<u8>>> for Niche
§type Archived = ArchivedOptionNonZeroU8
type Archived = ArchivedOptionNonZeroU8
The archived type of a
With<F, Self>
.source§impl ArchiveWith<Option<NonZero<usize>>> for Niche
impl ArchiveWith<Option<NonZero<usize>>> for Niche
§type Archived = ArchivedOptionNonZeroU32
type Archived = ArchivedOptionNonZeroU32
The archived type of a
With<F, Self>
.source§unsafe fn resolve_with(
field: &Option<NonZeroUsize>,
_: usize,
_: Self::Resolver,
out: *mut Self::Archived,
)
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 moresource§impl<T, D> DeserializeWith<ArchivedOptionBox<<T as ArchiveUnsized>::Archived>, Option<Box<T>>, D> for Niche
impl<T, D> DeserializeWith<ArchivedOptionBox<<T as ArchiveUnsized>::Archived>, Option<Box<T>>, D> for Niche
source§fn deserialize_with(
field: &ArchivedOptionBox<T::Archived>,
deserializer: &mut D,
) -> Result<Option<Box<T>>, D::Error>
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<NonZero<i128>>, D> for Niche
impl<D: Fallible + ?Sized> DeserializeWith<ArchivedOptionNonZeroI128, Option<NonZero<i128>>, D> for Niche
source§fn deserialize_with(
field: &ArchivedOptionNonZeroI128,
_: &mut D,
) -> Result<Option<NonZeroI128>, D::Error>
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<NonZero<i16>>, D> for Niche
impl<D: Fallible + ?Sized> DeserializeWith<ArchivedOptionNonZeroI16, Option<NonZero<i16>>, D> for Niche
source§fn deserialize_with(
field: &ArchivedOptionNonZeroI16,
_: &mut D,
) -> Result<Option<NonZeroI16>, D::Error>
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<NonZero<i32>>, D> for Niche
impl<D: Fallible + ?Sized> DeserializeWith<ArchivedOptionNonZeroI32, Option<NonZero<i32>>, D> for Niche
source§fn deserialize_with(
field: &ArchivedOptionNonZeroI32,
_: &mut D,
) -> Result<Option<NonZeroI32>, D::Error>
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<NonZero<isize>>, D> for Niche
impl<D: Fallible + ?Sized> DeserializeWith<ArchivedOptionNonZeroI32, Option<NonZero<isize>>, D> for Niche
source§fn deserialize_with(
field: &ArchivedOptionNonZeroI32,
_: &mut D,
) -> Result<Option<NonZeroIsize>, D::Error>
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<NonZero<i64>>, D> for Niche
impl<D: Fallible + ?Sized> DeserializeWith<ArchivedOptionNonZeroI64, Option<NonZero<i64>>, D> for Niche
source§fn deserialize_with(
field: &ArchivedOptionNonZeroI64,
_: &mut D,
) -> Result<Option<NonZeroI64>, D::Error>
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<NonZero<i8>>, D> for Niche
impl<D: Fallible + ?Sized> DeserializeWith<ArchivedOptionNonZeroI8, Option<NonZero<i8>>, D> for Niche
source§fn deserialize_with(
field: &ArchivedOptionNonZeroI8,
_: &mut D,
) -> Result<Option<NonZeroI8>, D::Error>
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<NonZero<u128>>, D> for Niche
impl<D: Fallible + ?Sized> DeserializeWith<ArchivedOptionNonZeroU128, Option<NonZero<u128>>, D> for Niche
source§fn deserialize_with(
field: &ArchivedOptionNonZeroU128,
_: &mut D,
) -> Result<Option<NonZeroU128>, D::Error>
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<NonZero<u16>>, D> for Niche
impl<D: Fallible + ?Sized> DeserializeWith<ArchivedOptionNonZeroU16, Option<NonZero<u16>>, D> for Niche
source§fn deserialize_with(
field: &ArchivedOptionNonZeroU16,
_: &mut D,
) -> Result<Option<NonZeroU16>, D::Error>
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<NonZero<u32>>, D> for Niche
impl<D: Fallible + ?Sized> DeserializeWith<ArchivedOptionNonZeroU32, Option<NonZero<u32>>, D> for Niche
source§fn deserialize_with(
field: &ArchivedOptionNonZeroU32,
_: &mut D,
) -> Result<Option<NonZeroU32>, D::Error>
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<NonZero<usize>>, D> for Niche
impl<D: Fallible + ?Sized> DeserializeWith<ArchivedOptionNonZeroU32, Option<NonZero<usize>>, D> for Niche
source§fn deserialize_with(
field: &ArchivedOptionNonZeroU32,
_: &mut D,
) -> Result<Option<NonZeroUsize>, D::Error>
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<NonZero<u64>>, D> for Niche
impl<D: Fallible + ?Sized> DeserializeWith<ArchivedOptionNonZeroU64, Option<NonZero<u64>>, D> for Niche
source§fn deserialize_with(
field: &ArchivedOptionNonZeroU64,
_: &mut D,
) -> Result<Option<NonZeroU64>, D::Error>
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<NonZero<u8>>, D> for Niche
impl<D: Fallible + ?Sized> DeserializeWith<ArchivedOptionNonZeroU8, Option<NonZero<u8>>, D> for Niche
source§fn deserialize_with(
field: &ArchivedOptionNonZeroU8,
_: &mut D,
) -> Result<Option<NonZeroU8>, D::Error>
fn deserialize_with( field: &ArchivedOptionNonZeroU8, _: &mut D, ) -> Result<Option<NonZeroU8>, D::Error>
Deserializes the field type
F
using the given deserializer.source§impl<S: Fallible + ?Sized> SerializeWith<Option<NonZero<i128>>, S> for Niche
impl<S: Fallible + ?Sized> SerializeWith<Option<NonZero<i128>>, S> for Niche
source§fn serialize_with(
_: &Option<NonZeroI128>,
_: &mut S,
) -> Result<Self::Resolver, S::Error>
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<NonZero<i16>>, S> for Niche
impl<S: Fallible + ?Sized> SerializeWith<Option<NonZero<i16>>, S> for Niche
source§fn serialize_with(
_: &Option<NonZeroI16>,
_: &mut S,
) -> Result<Self::Resolver, S::Error>
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<NonZero<i32>>, S> for Niche
impl<S: Fallible + ?Sized> SerializeWith<Option<NonZero<i32>>, S> for Niche
source§fn serialize_with(
_: &Option<NonZeroI32>,
_: &mut S,
) -> Result<Self::Resolver, S::Error>
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<NonZero<i64>>, S> for Niche
impl<S: Fallible + ?Sized> SerializeWith<Option<NonZero<i64>>, S> for Niche
source§fn serialize_with(
_: &Option<NonZeroI64>,
_: &mut S,
) -> Result<Self::Resolver, S::Error>
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<NonZero<isize>>, S> for Niche
impl<S: Fallible + ?Sized> SerializeWith<Option<NonZero<isize>>, S> for Niche
source§fn serialize_with(
_: &Option<NonZeroIsize>,
_: &mut S,
) -> Result<Self::Resolver, S::Error>
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<NonZero<u128>>, S> for Niche
impl<S: Fallible + ?Sized> SerializeWith<Option<NonZero<u128>>, S> for Niche
source§fn serialize_with(
_: &Option<NonZeroU128>,
_: &mut S,
) -> Result<Self::Resolver, S::Error>
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<NonZero<u16>>, S> for Niche
impl<S: Fallible + ?Sized> SerializeWith<Option<NonZero<u16>>, S> for Niche
source§fn serialize_with(
_: &Option<NonZeroU16>,
_: &mut S,
) -> Result<Self::Resolver, S::Error>
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<NonZero<u32>>, S> for Niche
impl<S: Fallible + ?Sized> SerializeWith<Option<NonZero<u32>>, S> for Niche
source§fn serialize_with(
_: &Option<NonZeroU32>,
_: &mut S,
) -> Result<Self::Resolver, S::Error>
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<NonZero<u64>>, S> for Niche
impl<S: Fallible + ?Sized> SerializeWith<Option<NonZero<u64>>, S> for Niche
source§fn serialize_with(
_: &Option<NonZeroU64>,
_: &mut S,
) -> Result<Self::Resolver, S::Error>
fn serialize_with( _: &Option<NonZeroU64>, _: &mut S, ) -> Result<Self::Resolver, S::Error>
Serializes the field type
F
using the given serializer.Auto Trait Implementations§
impl Freeze for Niche
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> ArchivePointee for T
impl<T> ArchivePointee for T
§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