pub struct OptionByte<T: Copy> { /* private fields */ }Expand description
Zero-copy tagged optional. See module docs for the layout and usage contract.
Implementations§
Source§impl<T: Copy> OptionByte<T>
impl<T: Copy> OptionByte<T>
Sourcepub const fn none(default_value: T) -> Self
pub const fn none(default_value: T) -> Self
Construct a None variant. Because the struct is #[repr(C)]
with a Pod value field, the value payload must still be
bitwise valid; the caller provides a default value that is
ignored by OptionByte::get.
Sourcepub const fn raw_tag(&self) -> u8
pub const fn raw_tag(&self) -> u8
The tag byte as the sender encoded it. Callers should never
inspect this directly; use OptionByte::get so the tag is
validated first.
Sourcepub fn get(&self) -> Result<Option<&T>, ProgramError>
pub fn get(&self) -> Result<Option<&T>, ProgramError>
Validate the tag byte and return the appropriate Rust Option.
Returns Err(ProgramError::InvalidInstructionData) when the
tag is neither 0 nor 1. Any other byte indicates malformed
instruction data and is the exact surface a Quasar OptionZc
would flag in validate_zc.
Sourcepub fn validate_tag(&self) -> ProgramResult
pub fn validate_tag(&self) -> ProgramResult
Validate-only: confirms the tag byte is 0 or 1. Useful for callers who want to reject malformed input early without taking a reference to the payload.
Trait Implementations§
Source§impl<T: Clone + Copy> Clone for OptionByte<T>
impl<T: Clone + Copy> Clone for OptionByte<T>
Source§fn clone(&self) -> OptionByte<T>
fn clone(&self) -> OptionByte<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more