#[repr(transparent)]pub struct PrefixedOptional<T>(pub Optional<T>);Expand description
An optional value prefixed by a boolean presence marker.
The wire format is a Boolean followed by T when the boolean is true:
Boolean(is present) + (is present ? T : nothing)Unlike Optional<T>, this type implements TypeCodec because its wire
representation contains its own presence marker. The marker is 0x01
when the wrapped value is Some, and 0x00 when it is
None.
§Examples
use mcproto_types::{TypeCodec, basic::UnsignedByte};
use mcproto_types::contextual::PrefixedOptional;
let value = PrefixedOptional::some(UnsignedByte(0xab));
let mut encoded = Vec::new();
value.encode(&mut encoded)?;
assert_eq!(encoded, [0x01, 0xab]);
let mut input = encoded.as_slice();
assert_eq!(PrefixedOptional::<UnsignedByte>::decode(&mut input)?, value);
assert!(input.is_empty());Tuple Fields§
§0: Optional<T>The optional value and its context-controlled encoding behavior.
Implementations§
Source§impl<T> PrefixedOptional<T>
impl<T> PrefixedOptional<T>
Sourcepub const fn as_ref(&self) -> PrefixedOptional<&T>
pub const fn as_ref(&self) -> PrefixedOptional<&T>
Returns the contained value by reference, if present.
Sourcepub fn into_option(self) -> Option<T>
pub fn into_option(self) -> Option<T>
Extracts the wrapped Option<T>.
Trait Implementations§
Source§impl<T: Clone> Clone for PrefixedOptional<T>
impl<T: Clone> Clone for PrefixedOptional<T>
Source§fn clone(&self) -> PrefixedOptional<T>
fn clone(&self) -> PrefixedOptional<T>
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<T: Debug> Debug for PrefixedOptional<T>
impl<T: Debug> Debug for PrefixedOptional<T>
Source§impl<T: Default> Default for PrefixedOptional<T>
impl<T: Default> Default for PrefixedOptional<T>
Source§fn default() -> PrefixedOptional<T>
fn default() -> PrefixedOptional<T>
Returns the “default value” for a type. Read more
impl<T: Eq> Eq for PrefixedOptional<T>
Source§impl<T> From<Option<T>> for PrefixedOptional<T>
impl<T> From<Option<T>> for PrefixedOptional<T>
Source§impl<T> From<Optional<T>> for PrefixedOptional<T>
impl<T> From<Optional<T>> for PrefixedOptional<T>
Source§impl<T> From<PrefixedOptional<T>> for Option<T>
impl<T> From<PrefixedOptional<T>> for Option<T>
Source§fn from(value: PrefixedOptional<T>) -> Self
fn from(value: PrefixedOptional<T>) -> Self
Converts to this type from the input type.
Source§impl<T: Hash> Hash for PrefixedOptional<T>
impl<T: Hash> Hash for PrefixedOptional<T>
Source§impl<T: PartialEq> PartialEq for PrefixedOptional<T>
impl<T: PartialEq> PartialEq for PrefixedOptional<T>
impl<T: PartialEq> StructuralPartialEq for PrefixedOptional<T>
Auto Trait Implementations§
impl<T> Freeze for PrefixedOptional<T>where
T: Freeze,
impl<T> RefUnwindSafe for PrefixedOptional<T>where
T: RefUnwindSafe,
impl<T> Send for PrefixedOptional<T>where
T: Send,
impl<T> Sync for PrefixedOptional<T>where
T: Sync,
impl<T> Unpin for PrefixedOptional<T>where
T: Unpin,
impl<T> UnsafeUnpin for PrefixedOptional<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for PrefixedOptional<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<T> ContextualCodec for Twhere
T: TypeCodec,
impl<T> ContextualCodec for Twhere
T: TypeCodec,
Source§fn encode_with_context(
&self,
writer: &mut impl Write,
_context: &Context,
) -> Result<(), CodecError>
fn encode_with_context( &self, writer: &mut impl Write, _context: &Context, ) -> Result<(), CodecError>
Encodes this value using context supplied by its enclosing structure.
Source§fn decode_with_context(
reader: &mut impl Read,
_context: &Context,
) -> Result<T, CodecError>where
T: Sized,
fn decode_with_context(
reader: &mut impl Read,
_context: &Context,
) -> Result<T, CodecError>where
T: Sized,
Decodes this value using context supplied by its enclosing structure.