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::{with::Niche, Archive, Archived};
#[derive(Archive)]
struct BasicExample {
value: Option<Box<str>>,
}
#[derive(Archive)]
struct NichedExample {
#[rkyv(with = Niche)]
value: Option<Box<str>>,
}
assert!(
size_of::<Archived<BasicExample>>()
> size_of::<Archived<NichedExample>>()
);Trait Implementations§
source§impl<T> ArchiveWith<Option<Box<T>>> for Niche
Available on crate feature alloc only.
impl<T> ArchiveWith<Option<Box<T>>> for Niche
Available on crate feature
alloc only.source§type Archived = ArchivedOptionBox<<T as ArchiveUnsized>::Archived>
type Archived = ArchivedOptionBox<<T as ArchiveUnsized>::Archived>
The archived type of
Self with F.source§type Resolver = OptionBoxResolver
type Resolver = OptionBoxResolver
The resolver of a
Self with F.source§impl ArchiveWith<Option<NonZero<i128>>> for Niche
impl ArchiveWith<Option<NonZero<i128>>> for Niche
source§type Archived = ArchivedOptionNonZeroI128
type Archived = ArchivedOptionNonZeroI128
The archived type of
Self with F.source§fn resolve_with(
field: &Option<NonZeroI128>,
_: Self::Resolver,
out: Place<Self::Archived>,
)
fn resolve_with( field: &Option<NonZeroI128>, _: Self::Resolver, out: Place<Self::Archived>, )
Resolves the archived type using a reference to the field type
F.source§impl ArchiveWith<Option<NonZero<i16>>> for Niche
impl ArchiveWith<Option<NonZero<i16>>> for Niche
source§type Archived = ArchivedOptionNonZeroI16
type Archived = ArchivedOptionNonZeroI16
The archived type of
Self with F.source§fn resolve_with(
field: &Option<NonZeroI16>,
_: Self::Resolver,
out: Place<Self::Archived>,
)
fn resolve_with( field: &Option<NonZeroI16>, _: Self::Resolver, out: Place<Self::Archived>, )
Resolves the archived type using a reference to the field type
F.source§impl ArchiveWith<Option<NonZero<i32>>> for Niche
impl ArchiveWith<Option<NonZero<i32>>> for Niche
source§type Archived = ArchivedOptionNonZeroI32
type Archived = ArchivedOptionNonZeroI32
The archived type of
Self with F.source§fn resolve_with(
field: &Option<NonZeroI32>,
_: Self::Resolver,
out: Place<Self::Archived>,
)
fn resolve_with( field: &Option<NonZeroI32>, _: Self::Resolver, out: Place<Self::Archived>, )
Resolves the archived type using a reference to the field type
F.source§impl ArchiveWith<Option<NonZero<i64>>> for Niche
impl ArchiveWith<Option<NonZero<i64>>> for Niche
source§type Archived = ArchivedOptionNonZeroI64
type Archived = ArchivedOptionNonZeroI64
The archived type of
Self with F.source§fn resolve_with(
field: &Option<NonZeroI64>,
_: Self::Resolver,
out: Place<Self::Archived>,
)
fn resolve_with( field: &Option<NonZeroI64>, _: Self::Resolver, out: Place<Self::Archived>, )
Resolves the archived type using a reference to the field type
F.source§impl ArchiveWith<Option<NonZero<isize>>> for Niche
impl ArchiveWith<Option<NonZero<isize>>> for Niche
source§type Archived = ArchivedOptionNonZeroI32
type Archived = ArchivedOptionNonZeroI32
The archived type of
Self with F.source§fn resolve_with(
field: &Option<NonZeroIsize>,
_: Self::Resolver,
out: Place<Self::Archived>,
)
fn resolve_with( field: &Option<NonZeroIsize>, _: Self::Resolver, out: Place<Self::Archived>, )
Resolves the archived type using a reference to the field type
F.source§impl ArchiveWith<Option<NonZero<u128>>> for Niche
impl ArchiveWith<Option<NonZero<u128>>> for Niche
source§type Archived = ArchivedOptionNonZeroU128
type Archived = ArchivedOptionNonZeroU128
The archived type of
Self with F.source§fn resolve_with(
field: &Option<NonZeroU128>,
_: Self::Resolver,
out: Place<Self::Archived>,
)
fn resolve_with( field: &Option<NonZeroU128>, _: Self::Resolver, out: Place<Self::Archived>, )
Resolves the archived type using a reference to the field type
F.source§impl ArchiveWith<Option<NonZero<u16>>> for Niche
impl ArchiveWith<Option<NonZero<u16>>> for Niche
source§type Archived = ArchivedOptionNonZeroU16
type Archived = ArchivedOptionNonZeroU16
The archived type of
Self with F.source§fn resolve_with(
field: &Option<NonZeroU16>,
_: Self::Resolver,
out: Place<Self::Archived>,
)
fn resolve_with( field: &Option<NonZeroU16>, _: Self::Resolver, out: Place<Self::Archived>, )
Resolves the archived type using a reference to the field type
F.source§impl ArchiveWith<Option<NonZero<u32>>> for Niche
impl ArchiveWith<Option<NonZero<u32>>> for Niche
source§type Archived = ArchivedOptionNonZeroU32
type Archived = ArchivedOptionNonZeroU32
The archived type of
Self with F.source§fn resolve_with(
field: &Option<NonZeroU32>,
_: Self::Resolver,
out: Place<Self::Archived>,
)
fn resolve_with( field: &Option<NonZeroU32>, _: Self::Resolver, out: Place<Self::Archived>, )
Resolves the archived type using a reference to the field type
F.source§impl ArchiveWith<Option<NonZero<u64>>> for Niche
impl ArchiveWith<Option<NonZero<u64>>> for Niche
source§type Archived = ArchivedOptionNonZeroU64
type Archived = ArchivedOptionNonZeroU64
The archived type of
Self with F.source§fn resolve_with(
field: &Option<NonZeroU64>,
_: Self::Resolver,
out: Place<Self::Archived>,
)
fn resolve_with( field: &Option<NonZeroU64>, _: Self::Resolver, out: Place<Self::Archived>, )
Resolves the archived type using a reference to the field type
F.source§impl ArchiveWith<Option<NonZero<usize>>> for Niche
impl ArchiveWith<Option<NonZero<usize>>> for Niche
source§type Archived = ArchivedOptionNonZeroU32
type Archived = ArchivedOptionNonZeroU32
The archived type of
Self with F.source§fn resolve_with(
field: &Option<NonZeroUsize>,
_: Self::Resolver,
out: Place<Self::Archived>,
)
fn resolve_with( field: &Option<NonZeroUsize>, _: Self::Resolver, out: Place<Self::Archived>, )
Resolves the archived type using a reference to the field type
F.source§impl<T, D> DeserializeWith<ArchivedOptionBox<<T as ArchiveUnsized>::Archived>, Option<Box<T>>, D> for Nichewhere
T: ArchiveUnsized + LayoutRaw + Pointee + ?Sized,
T::Archived: DeserializeUnsized<T, D>,
D: Fallible + ?Sized,
D::Error: Source,
Available on crate feature alloc only.
impl<T, D> DeserializeWith<ArchivedOptionBox<<T as ArchiveUnsized>::Archived>, Option<Box<T>>, D> for Nichewhere
T: ArchiveUnsized + LayoutRaw + Pointee + ?Sized,
T::Archived: DeserializeUnsized<T, D>,
D: Fallible + ?Sized,
D::Error: Source,
Available on crate feature
alloc only.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> DeserializeWith<ArchivedOptionNonZeroI128, Option<NonZero<i128>>, D> for Niche
impl<D> 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> DeserializeWith<ArchivedOptionNonZeroI16, Option<NonZero<i16>>, D> for Niche
impl<D> 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> DeserializeWith<ArchivedOptionNonZeroI32, Option<NonZero<i32>>, D> for Niche
impl<D> 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> DeserializeWith<ArchivedOptionNonZeroI32, Option<NonZero<isize>>, D> for Niche
impl<D> DeserializeWith<ArchivedOptionNonZeroI32, Option<NonZero<isize>>, D> for Niche
source§fn deserialize_with(
field: &ArchivedOptionNonZeroIsize,
_: &mut D,
) -> Result<Option<NonZeroIsize>, D::Error>
fn deserialize_with( field: &ArchivedOptionNonZeroIsize, _: &mut D, ) -> Result<Option<NonZeroIsize>, D::Error>
Deserializes the field type
F using the given deserializer.source§impl<D> DeserializeWith<ArchivedOptionNonZeroI64, Option<NonZero<i64>>, D> for Niche
impl<D> 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> DeserializeWith<ArchivedOptionNonZeroI8, Option<NonZero<i8>>, D> for Niche
impl<D> 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> DeserializeWith<ArchivedOptionNonZeroU128, Option<NonZero<u128>>, D> for Niche
impl<D> 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> DeserializeWith<ArchivedOptionNonZeroU16, Option<NonZero<u16>>, D> for Niche
impl<D> 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> DeserializeWith<ArchivedOptionNonZeroU32, Option<NonZero<u32>>, D> for Niche
impl<D> 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> DeserializeWith<ArchivedOptionNonZeroU32, Option<NonZero<usize>>, D> for Niche
impl<D> DeserializeWith<ArchivedOptionNonZeroU32, Option<NonZero<usize>>, D> for Niche
source§fn deserialize_with(
field: &ArchivedOptionNonZeroUsize,
_: &mut D,
) -> Result<Option<NonZeroUsize>, D::Error>
fn deserialize_with( field: &ArchivedOptionNonZeroUsize, _: &mut D, ) -> Result<Option<NonZeroUsize>, D::Error>
Deserializes the field type
F using the given deserializer.source§impl<D> DeserializeWith<ArchivedOptionNonZeroU64, Option<NonZero<u64>>, D> for Niche
impl<D> 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> DeserializeWith<ArchivedOptionNonZeroU8, Option<NonZero<u8>>, D> for Niche
impl<D> 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
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.