#[repr(C)]pub struct NullableOption<T: Nullable>(/* private fields */);
Expand description
Borsh encodes standard Option
s with either a 1 or 0 representing the Some
or None variants. This means an
Optionfor example, is alternately encoded as 33 bytes or 1 byte.
NullableOptiontype allows creating a fixed-size generic
Optiontype that can be used as an
Optionwithout requiring extra space to indicate if the value is
Someor
None. In the
Pubkey` example it is now
always 32 bytes making it friendly to getProgramAccount calls and creating fixed-size on-chain accounts.
This requires T
to implement the Nullable
trait so that it defines a NONE
value and can indicate if it is Some
or None
.
Implementations§
Trait Implementations§
Source§impl<T: Nullable> BorshDeserialize for NullableOption<T>
impl<T: Nullable> BorshDeserialize for NullableOption<T>
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: Nullable> BorshSerialize for NullableOption<T>
impl<T: Nullable> BorshSerialize for NullableOption<T>
Source§impl<T: Clone + Nullable> Clone for NullableOption<T>
impl<T: Clone + Nullable> Clone for NullableOption<T>
Source§fn clone(&self) -> NullableOption<T>
fn clone(&self) -> NullableOption<T>
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl<T: Nullable> Default for NullableOption<T>
impl<T: Nullable> Default for NullableOption<T>
impl<T: Copy + Nullable> Copy for NullableOption<T>
impl<T: Eq + Nullable> Eq for NullableOption<T>
impl<T: Nullable> StructuralPartialEq for NullableOption<T>
Auto Trait Implementations§
impl<T> Freeze for NullableOption<T>where
T: Freeze,
impl<T> RefUnwindSafe for NullableOption<T>where
T: RefUnwindSafe,
impl<T> Send for NullableOption<T>where
T: Send,
impl<T> Sync for NullableOption<T>where
T: Sync,
impl<T> Unpin for NullableOption<T>where
T: Unpin,
impl<T> UnwindSafe for NullableOption<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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more