pub struct MaybeNull<T: Nullable>(/* private fields */);Expand description
A wrapper that can be used as an Option<T> without requiring extra space
to indicate whether the value is Some or None.
This can be used when a specific value of T indicates that its value is
None.
Implementations§
Trait Implementations§
Source§impl<T> BorshDeserialize for MaybeNull<T>where
T: BorshDeserialize + Nullable,
impl<T> BorshDeserialize for MaybeNull<T>where
T: BorshDeserialize + Nullable,
fn deserialize_reader<__R: Read>(reader: &mut __R) -> Result<Self, Error>
Source§fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>
fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>
Deserializes this instance from a given slice of bytes.
Updates the buffer to point at the remaining bytes.
Source§fn try_from_slice(v: &[u8]) -> Result<Self, Error>
fn try_from_slice(v: &[u8]) -> Result<Self, Error>
Deserialize this instance from a slice of bytes.
fn try_from_reader<R>(reader: &mut R) -> Result<Self, Error>where
R: Read,
Source§impl<T> BorshSchema for MaybeNull<T>where
T: BorshSchema + Nullable,
impl<T> BorshSchema for MaybeNull<T>where
T: BorshSchema + Nullable,
Source§fn declaration() -> Declaration
fn declaration() -> Declaration
Get the name of the type without brackets.
Source§fn add_definitions_recursively(
definitions: &mut BTreeMap<Declaration, Definition>,
)
fn add_definitions_recursively( definitions: &mut BTreeMap<Declaration, Definition>, )
Recursively, using DFS, add type definitions required for this type.
Type definition partially explains how to serialize/deserialize a type.
Source§impl<T> BorshSerialize for MaybeNull<T>where
T: BorshSerialize + Nullable,
impl<T> BorshSerialize for MaybeNull<T>where
T: BorshSerialize + Nullable,
Source§impl<'de, T> Deserialize<'de> for MaybeNull<T>where
T: Nullable + Deserialize<'de>,
Available on crate feature serde only.
impl<'de, T> Deserialize<'de> for MaybeNull<T>where
T: Nullable + Deserialize<'de>,
Available on crate feature
serde only.Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl<'de, T, U> DeserializeAs<'de, MaybeNull<T>> for Option<U>where
T: Nullable,
U: DeserializeAs<'de, T>,
Available on crate feature serde-with only.
impl<'de, T, U> DeserializeAs<'de, MaybeNull<T>> for Option<U>where
T: Nullable,
U: DeserializeAs<'de, T>,
Available on crate feature
serde-with only.Source§fn deserialize_as<D>(deserializer: D) -> Result<MaybeNull<T>, D::Error>where
D: Deserializer<'de>,
fn deserialize_as<D>(deserializer: D) -> Result<MaybeNull<T>, D::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer.
Source§impl<'de, T, WincodeConfig: Config> SchemaRead<'de, WincodeConfig> for MaybeNull<T>where
T: SchemaRead<'de, WincodeConfig, Dst = T> + Nullable,
impl<'de, T, WincodeConfig: Config> SchemaRead<'de, WincodeConfig> for MaybeNull<T>where
T: SchemaRead<'de, WincodeConfig, Dst = T> + Nullable,
Source§impl<T, WincodeConfig: Config> SchemaWrite<WincodeConfig> for MaybeNull<T>where
T: SchemaWrite<WincodeConfig, Src = T> + Nullable,
impl<T, WincodeConfig: Config> SchemaWrite<WincodeConfig> for MaybeNull<T>where
T: SchemaWrite<WincodeConfig, Src = T> + Nullable,
Source§impl<T, U> SerializeAs<MaybeNull<T>> for Option<U>where
T: Nullable,
U: SerializeAs<T>,
Available on crate feature serde-with only.
impl<T, U> SerializeAs<MaybeNull<T>> for Option<U>where
T: Nullable,
U: SerializeAs<T>,
Available on crate feature
serde-with only.Source§fn serialize_as<S>(
source: &MaybeNull<T>,
serializer: S,
) -> Result<S::Ok, S::Error>where
S: Serializer,
fn serialize_as<S>(
source: &MaybeNull<T>,
serializer: S,
) -> Result<S::Ok, S::Error>where
S: Serializer,
Serialize this value into the given Serde serializer.
Source§impl<T, C> ZeroCopy<C> for MaybeNull<T>
Available on crate feature wincode only.§Safety
MaybeNull<T> where T: ZeroCopy is trivially zero-copy.
impl<T, C> ZeroCopy<C> for MaybeNull<T>
Available on crate feature
wincode only.§Safety
MaybeNull<T> where T: ZeroCopy is trivially zero-copy.
Source§fn from_bytes<'de>(bytes: &'de [u8], config: C) -> Result<&'de Self, ReadError>where
Self: Sized + SchemaRead<'de, C, Dst = Self>,
fn from_bytes<'de>(bytes: &'de [u8], config: C) -> Result<&'de Self, ReadError>where
Self: Sized + SchemaRead<'de, C, Dst = Self>,
Like
crate::ZeroCopy::from_bytes, but allows the caller to provide a custom configuration.Source§fn from_bytes_mut<'de>(
bytes: &'de mut [u8],
config: C,
) -> Result<&'de mut Self, ReadError>where
Self: Sized + SchemaRead<'de, C, Dst = Self>,
fn from_bytes_mut<'de>(
bytes: &'de mut [u8],
config: C,
) -> Result<&'de mut Self, ReadError>where
Self: Sized + SchemaRead<'de, C, Dst = Self>,
Like
crate::ZeroCopy::from_bytes_mut, but allows the caller to provide a custom configuration.Source§impl<T: Nullable + Zeroable> Zeroable for MaybeNull<T>
Available on crate feature bytemuck only.§Safety
MaybeNull is a transparent wrapper around a bytemuck Pod type T with
identical data representation.
impl<T: Nullable + Zeroable> Zeroable for MaybeNull<T>
Available on crate feature
bytemuck only.§Safety
MaybeNull is a transparent wrapper around a bytemuck Pod type T with
identical data representation.
impl<T: Copy + Nullable> Copy for MaybeNull<T>
impl<T: Eq + Nullable> Eq for MaybeNull<T>
impl<T: Nullable + Pod> Pod for MaybeNull<T>
Available on crate feature
bytemuck only.§Safety
MaybeNull is a transparent wrapper around a bytemuck Pod type T with
identical data representation.
impl<T: Nullable> StructuralPartialEq for MaybeNull<T>
Auto Trait Implementations§
impl<T> Freeze for MaybeNull<T>where
T: Freeze,
impl<T> RefUnwindSafe for MaybeNull<T>where
T: RefUnwindSafe,
impl<T> Send for MaybeNull<T>where
T: Send,
impl<T> Sync for MaybeNull<T>where
T: Sync,
impl<T> Unpin for MaybeNull<T>where
T: Unpin,
impl<T> UnsafeUnpin for MaybeNull<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for MaybeNull<T>where
T: UnwindSafe,
Blanket Implementations§
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> CheckedBitPattern for Twhere
T: AnyBitPattern,
impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,
Source§type Bits = T
type Bits = T
Self must have the same layout as the specified Bits except for
the possible invalid bit patterns being checked during
is_valid_bit_pattern.Source§fn is_valid_bit_pattern(_bits: &T) -> bool
fn is_valid_bit_pattern(_bits: &T) -> bool
If this function returns true, then it must be valid to reinterpret
bits
as &Self.Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<'de, T> Deserialize<'de> for Twhere
T: SchemaRead<'de, Configuration>,
impl<'de, T> Deserialize<'de> for Twhere
T: SchemaRead<'de, Configuration>,
Source§impl<'de, T, C> Deserialize<'de, C> for Twhere
C: Config,
T: SchemaRead<'de, C>,
impl<'de, T, C> Deserialize<'de, C> for Twhere
C: Config,
T: SchemaRead<'de, C>,
Source§impl<T, C> DeserializeOwned<C> for Twhere
C: Config,
T: SchemaReadOwned<C>,
impl<T, C> DeserializeOwned<C> for Twhere
C: Config,
T: SchemaReadOwned<C>,
Source§fn deserialize_from<'de>(src: impl Reader<'de>) -> Result<Self::Dst, ReadError>
fn deserialize_from<'de>(src: impl Reader<'de>) -> Result<Self::Dst, ReadError>
Deserialize from the given
Reader into a new Self::Dst.Source§fn deserialize_from_into<'de>(
src: impl Reader<'de>,
dst: &mut MaybeUninit<Self::Dst>,
) -> Result<(), ReadError>
fn deserialize_from_into<'de>( src: impl Reader<'de>, dst: &mut MaybeUninit<Self::Dst>, ) -> Result<(), ReadError>
Deserialize from the given
Reader into dst.Source§impl<T> DeserializeOwned for Twhere
T: SchemaReadOwned<Configuration>,
impl<T> DeserializeOwned for Twhere
T: SchemaReadOwned<Configuration>,
Source§fn deserialize_from<'de>(src: impl Reader<'de>) -> Result<Self::Dst, ReadError>
fn deserialize_from<'de>(src: impl Reader<'de>) -> Result<Self::Dst, ReadError>
Deserialize from the given
Reader into a new Self::Dst.Source§fn deserialize_from_into<'de>(
src: impl Reader<'de>,
dst: &mut MaybeUninit<Self::Dst>,
) -> Result<(), ReadError>
fn deserialize_from_into<'de>( src: impl Reader<'de>, dst: &mut MaybeUninit<Self::Dst>, ) -> Result<(), ReadError>
Deserialize from the given
Reader into dst.Source§impl<T, C> Serialize<C> for T
impl<T, C> Serialize<C> for T
Source§fn serialize_into(
dst: impl Writer,
src: &Self::Src,
config: C,
) -> Result<(), WriteError>
fn serialize_into( dst: impl Writer, src: &Self::Src, config: C, ) -> Result<(), WriteError>
Serialize a serializable type into the given
Writer.Source§fn serialized_size(src: &Self::Src, config: C) -> Result<u64, WriteError>
fn serialized_size(src: &Self::Src, config: C) -> Result<u64, WriteError>
Get the size in bytes of the type when serialized.
Source§impl<T> Serialize for T
impl<T> Serialize for T
Source§fn serialize_into(dst: impl Writer, src: &Self::Src) -> Result<(), WriteError>
fn serialize_into(dst: impl Writer, src: &Self::Src) -> Result<(), WriteError>
Serialize a serializable type into the given byte buffer.
Source§fn serialized_size(src: &Self::Src) -> Result<u64, WriteError>
fn serialized_size(src: &Self::Src) -> Result<u64, WriteError>
Get the size in bytes of the type when serialized.