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
sourceimpl<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>
.
sourceimpl 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>
.
sourceunsafe 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 more
sourceimpl 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>
.
sourceunsafe 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 more
sourceimpl 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>
.
sourceunsafe 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 more
sourceimpl 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>
.
sourceunsafe 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 more
sourceimpl 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>
.
sourceimpl 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>
.
sourceunsafe 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 more
sourceimpl 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>
.
sourceunsafe 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 more
sourceimpl 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>
.
sourceunsafe 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 more
sourceimpl 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>
.
sourceunsafe 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 more
sourceimpl 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>
.
sourceunsafe 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 more
sourceimpl 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>
.
sourceimpl 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>
.
sourceunsafe 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 more
sourceimpl<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,
sourcefn 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.
sourceimpl<D: Fallible + ?Sized> DeserializeWith<ArchivedOptionNonZeroI128, Option<NonZeroI128>, D> for Niche
impl<D: Fallible + ?Sized> DeserializeWith<ArchivedOptionNonZeroI128, Option<NonZeroI128>, D> for Niche
sourcefn 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.
sourceimpl<D: Fallible + ?Sized> DeserializeWith<ArchivedOptionNonZeroI16, Option<NonZeroI16>, D> for Niche
impl<D: Fallible + ?Sized> DeserializeWith<ArchivedOptionNonZeroI16, Option<NonZeroI16>, D> for Niche
sourcefn 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.
sourceimpl<D: Fallible + ?Sized> DeserializeWith<ArchivedOptionNonZeroI32, Option<NonZeroI32>, D> for Niche
impl<D: Fallible + ?Sized> DeserializeWith<ArchivedOptionNonZeroI32, Option<NonZeroI32>, D> for Niche
sourcefn 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.
sourceimpl<D: Fallible + ?Sized> DeserializeWith<ArchivedOptionNonZeroI32, Option<NonZeroIsize>, D> for Niche
impl<D: Fallible + ?Sized> DeserializeWith<ArchivedOptionNonZeroI32, Option<NonZeroIsize>, D> for Niche
sourcefn 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.
sourceimpl<D: Fallible + ?Sized> DeserializeWith<ArchivedOptionNonZeroI64, Option<NonZeroI64>, D> for Niche
impl<D: Fallible + ?Sized> DeserializeWith<ArchivedOptionNonZeroI64, Option<NonZeroI64>, D> for Niche
sourcefn 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.
sourceimpl<D: Fallible + ?Sized> DeserializeWith<ArchivedOptionNonZeroI8, Option<NonZeroI8>, D> for Niche
impl<D: Fallible + ?Sized> DeserializeWith<ArchivedOptionNonZeroI8, Option<NonZeroI8>, D> for Niche
sourcefn 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.
sourceimpl<D: Fallible + ?Sized> DeserializeWith<ArchivedOptionNonZeroU128, Option<NonZeroU128>, D> for Niche
impl<D: Fallible + ?Sized> DeserializeWith<ArchivedOptionNonZeroU128, Option<NonZeroU128>, D> for Niche
sourcefn 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.
sourceimpl<D: Fallible + ?Sized> DeserializeWith<ArchivedOptionNonZeroU16, Option<NonZeroU16>, D> for Niche
impl<D: Fallible + ?Sized> DeserializeWith<ArchivedOptionNonZeroU16, Option<NonZeroU16>, D> for Niche
sourcefn 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.
sourceimpl<D: Fallible + ?Sized> DeserializeWith<ArchivedOptionNonZeroU32, Option<NonZeroU32>, D> for Niche
impl<D: Fallible + ?Sized> DeserializeWith<ArchivedOptionNonZeroU32, Option<NonZeroU32>, D> for Niche
sourcefn 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.
sourceimpl<D: Fallible + ?Sized> DeserializeWith<ArchivedOptionNonZeroU32, Option<NonZeroUsize>, D> for Niche
impl<D: Fallible + ?Sized> DeserializeWith<ArchivedOptionNonZeroU32, Option<NonZeroUsize>, D> for Niche
sourcefn 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.
sourceimpl<D: Fallible + ?Sized> DeserializeWith<ArchivedOptionNonZeroU64, Option<NonZeroU64>, D> for Niche
impl<D: Fallible + ?Sized> DeserializeWith<ArchivedOptionNonZeroU64, Option<NonZeroU64>, D> for Niche
sourcefn 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.
sourceimpl<D: Fallible + ?Sized> DeserializeWith<ArchivedOptionNonZeroU8, Option<NonZeroU8>, D> for Niche
impl<D: Fallible + ?Sized> DeserializeWith<ArchivedOptionNonZeroU8, Option<NonZeroU8>, D> for Niche
sourcefn 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.
sourceimpl<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,
sourceimpl<S: Fallible + ?Sized> SerializeWith<Option<NonZeroI128>, S> for Niche
impl<S: Fallible + ?Sized> SerializeWith<Option<NonZeroI128>, S> for Niche
sourcefn 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.
sourceimpl<S: Fallible + ?Sized> SerializeWith<Option<NonZeroI16>, S> for Niche
impl<S: Fallible + ?Sized> SerializeWith<Option<NonZeroI16>, S> for Niche
sourcefn 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.
sourceimpl<S: Fallible + ?Sized> SerializeWith<Option<NonZeroI32>, S> for Niche
impl<S: Fallible + ?Sized> SerializeWith<Option<NonZeroI32>, S> for Niche
sourcefn 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.
sourceimpl<S: Fallible + ?Sized> SerializeWith<Option<NonZeroI64>, S> for Niche
impl<S: Fallible + ?Sized> SerializeWith<Option<NonZeroI64>, S> for Niche
sourcefn 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.
sourceimpl<S: Fallible + ?Sized> SerializeWith<Option<NonZeroIsize>, S> for Niche
impl<S: Fallible + ?Sized> SerializeWith<Option<NonZeroIsize>, S> for Niche
sourcefn 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.
sourceimpl<S: Fallible + ?Sized> SerializeWith<Option<NonZeroU128>, S> for Niche
impl<S: Fallible + ?Sized> SerializeWith<Option<NonZeroU128>, S> for Niche
sourcefn 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.
sourceimpl<S: Fallible + ?Sized> SerializeWith<Option<NonZeroU16>, S> for Niche
impl<S: Fallible + ?Sized> SerializeWith<Option<NonZeroU16>, S> for Niche
sourcefn 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.
sourceimpl<S: Fallible + ?Sized> SerializeWith<Option<NonZeroU32>, S> for Niche
impl<S: Fallible + ?Sized> SerializeWith<Option<NonZeroU32>, S> for Niche
sourcefn 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.
sourceimpl<S: Fallible + ?Sized> SerializeWith<Option<NonZeroU64>, S> for Niche
impl<S: Fallible + ?Sized> SerializeWith<Option<NonZeroU64>, S> for Niche
sourcefn 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.
sourceimpl<S: Fallible + ?Sized> SerializeWith<Option<NonZeroUsize>, S> for Niche
impl<S: Fallible + ?Sized> SerializeWith<Option<NonZeroUsize>, S> for Niche
sourcefn 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
sourceimpl<T> ArchivePointee for T
impl<T> ArchivePointee for T
type ArchivedMetadata = ()
type ArchivedMetadata = ()
The archived version of the pointer metadata for this type.
sourcefn pointer_metadata(_: &Self::ArchivedMetadata) -> <Self as Pointee>::Metadata
fn pointer_metadata(_: &Self::ArchivedMetadata) -> <Self as Pointee>::Metadata
Converts some archived metadata to the pointer metadata for itself.
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more