Struct rkyv::with::Niche [−][src]
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
impl<T: ArchiveUnsized + ?Sized> ArchiveWith<Option<Box<T, Global>>> for Niche where
ArchivedMetadata<T>: Default,
impl<T: ArchiveUnsized + ?Sized> ArchiveWith<Option<Box<T, Global>>> for Niche where
ArchivedMetadata<T>: Default,
type Archived = ArchivedOptionBox<T::Archived>
type Archived = ArchivedOptionBox<T::Archived>
The archived type of a With<F, Self>
.
type Resolver = OptionBoxResolver<T::MetadataResolver>
type Resolver = OptionBoxResolver<T::MetadataResolver>
The resolver of a With<F, Self>
.
impl<T, D> DeserializeWith<ArchivedOptionBox<<T as ArchiveUnsized>::Archived>, Option<Box<T, Global>>, D> for Niche where
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 Niche where
T: ArchiveUnsized + ?Sized,
T::Archived: DeserializeUnsized<T, D>,
D: Fallible + ?Sized,
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.
impl<T, S> SerializeWith<Option<Box<T, Global>>, S> for Niche where
T: SerializeUnsized<S> + ?Sized,
S: Serializer + ?Sized,
ArchivedMetadata<T>: Default,
impl<T, S> SerializeWith<Option<Box<T, Global>>, S> for Niche where
T: SerializeUnsized<S> + ?Sized,
S: Serializer + ?Sized,
ArchivedMetadata<T>: Default,
Auto Trait Implementations
impl RefUnwindSafe for Niche
impl UnwindSafe for Niche
Blanket Implementations
type ArchivedMetadata = ()
type ArchivedMetadata = ()
The archived version of the pointer metadata for this type.
Converts some archived metadata to the pointer metadata for itself.
Mutably borrows from an owned value. Read more