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,
impl<T: ArchiveUnsized + ?Sized> ArchiveWith<Option<Box<T, Global>>> 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<NonZeroI128>> for Niche
impl ArchiveWith<Option<NonZeroI128>> 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<NonZeroI16>> for Niche
impl ArchiveWith<Option<NonZeroI16>> 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<NonZeroI32>> for Niche
impl ArchiveWith<Option<NonZeroI32>> 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<NonZeroI64>> for Niche
impl ArchiveWith<Option<NonZeroI64>> 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<NonZeroI8>> for Niche
impl ArchiveWith<Option<NonZeroI8>> for Niche
§type Archived = ArchivedOptionNonZeroI8
type Archived = ArchivedOptionNonZeroI8
The archived type of a
With<F, Self>
.source§impl ArchiveWith<Option<NonZeroIsize>> for Niche
impl ArchiveWith<Option<NonZeroIsize>> 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<NonZeroU128>> for Niche
impl ArchiveWith<Option<NonZeroU128>> 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<NonZeroU16>> for Niche
impl ArchiveWith<Option<NonZeroU16>> 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<NonZeroU32>> for Niche
impl ArchiveWith<Option<NonZeroU32>> 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<NonZeroU64>> for Niche
impl ArchiveWith<Option<NonZeroU64>> 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<NonZeroU8>> for Niche
impl ArchiveWith<Option<NonZeroU8>> for Niche
§type Archived = ArchivedOptionNonZeroU8
type Archived = ArchivedOptionNonZeroU8
The archived type of a
With<F, Self>
.source§impl ArchiveWith<Option<NonZeroUsize>> for Niche
impl ArchiveWith<Option<NonZeroUsize>> 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, Global>>, D> for Nichewhere
T: ArchiveUnsized + ?Sized,
T::Archived: DeserializeUnsized<T, D>,
D: Fallible + ?Sized,
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>
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
impl<D: Fallible + ?Sized> DeserializeWith<ArchivedOptionNonZeroI128, Option<NonZeroI128>, 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<NonZeroI16>, D> for Niche
impl<D: Fallible + ?Sized> DeserializeWith<ArchivedOptionNonZeroI16, Option<NonZeroI16>, 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<NonZeroI32>, D> for Niche
impl<D: Fallible + ?Sized> DeserializeWith<ArchivedOptionNonZeroI32, Option<NonZeroI32>, 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<NonZeroIsize>, D> for Niche
impl<D: Fallible + ?Sized> DeserializeWith<ArchivedOptionNonZeroI32, Option<NonZeroIsize>, 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<NonZeroI64>, D> for Niche
impl<D: Fallible + ?Sized> DeserializeWith<ArchivedOptionNonZeroI64, Option<NonZeroI64>, 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<NonZeroI8>, D> for Niche
impl<D: Fallible + ?Sized> DeserializeWith<ArchivedOptionNonZeroI8, Option<NonZeroI8>, 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<NonZeroU128>, D> for Niche
impl<D: Fallible + ?Sized> DeserializeWith<ArchivedOptionNonZeroU128, Option<NonZeroU128>, 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<NonZeroU16>, D> for Niche
impl<D: Fallible + ?Sized> DeserializeWith<ArchivedOptionNonZeroU16, Option<NonZeroU16>, 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<NonZeroU32>, D> for Niche
impl<D: Fallible + ?Sized> DeserializeWith<ArchivedOptionNonZeroU32, Option<NonZeroU32>, 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<NonZeroUsize>, D> for Niche
impl<D: Fallible + ?Sized> DeserializeWith<ArchivedOptionNonZeroU32, Option<NonZeroUsize>, 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<NonZeroU64>, D> for Niche
impl<D: Fallible + ?Sized> DeserializeWith<ArchivedOptionNonZeroU64, Option<NonZeroU64>, 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<NonZeroU8>, D> for Niche
impl<D: Fallible + ?Sized> DeserializeWith<ArchivedOptionNonZeroU8, Option<NonZeroU8>, 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<T, S> SerializeWith<Option<Box<T, Global>>, S> for Nichewhere
T: SerializeUnsized<S> + ?Sized,
S: Serializer + ?Sized,
ArchivedMetadata<T>: Default,
impl<T, S> SerializeWith<Option<Box<T, Global>>, S> for Nichewhere T: SerializeUnsized<S> + ?Sized, S: Serializer + ?Sized, ArchivedMetadata<T>: Default,
source§impl<S: Fallible + ?Sized> SerializeWith<Option<NonZeroI128>, S> for Niche
impl<S: Fallible + ?Sized> SerializeWith<Option<NonZeroI128>, 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<NonZeroI16>, S> for Niche
impl<S: Fallible + ?Sized> SerializeWith<Option<NonZeroI16>, 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<NonZeroI32>, S> for Niche
impl<S: Fallible + ?Sized> SerializeWith<Option<NonZeroI32>, 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<NonZeroI64>, S> for Niche
impl<S: Fallible + ?Sized> SerializeWith<Option<NonZeroI64>, 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<NonZeroIsize>, S> for Niche
impl<S: Fallible + ?Sized> SerializeWith<Option<NonZeroIsize>, 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<NonZeroU128>, S> for Niche
impl<S: Fallible + ?Sized> SerializeWith<Option<NonZeroU128>, 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<NonZeroU16>, S> for Niche
impl<S: Fallible + ?Sized> SerializeWith<Option<NonZeroU16>, 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<NonZeroU32>, S> for Niche
impl<S: Fallible + ?Sized> SerializeWith<Option<NonZeroU32>, 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<NonZeroU64>, S> for Niche
impl<S: Fallible + ?Sized> SerializeWith<Option<NonZeroU64>, 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.source§impl<S: Fallible + ?Sized> SerializeWith<Option<NonZeroUsize>, S> for Niche
impl<S: Fallible + ?Sized> SerializeWith<Option<NonZeroUsize>, S> for Niche
source§fn serialize_with(
_: &Option<NonZeroUsize>,
_: &mut S
) -> Result<Self::Resolver, S::Error>
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> 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<F, W, T, D> Deserialize<With<T, W>, D> for Fwhere
W: DeserializeWith<F, T, D>,
D: Fallible + ?Sized,
F: ?Sized,
impl<F, W, T, D> Deserialize<With<T, W>, D> for Fwhere W: DeserializeWith<F, T, D>, D: Fallible + ?Sized, F: ?Sized,
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>
Gets the layout of the type.