pub struct Context { /* private fields */ }Expand description
External information required to encode or decode a contextual value.
The initial context records whether the current field is present. This is
intended for protocol fields described as Optional X, where no presence
marker is encoded and the field’s presence must be known from its enclosing
packet or data structure.
A Context does not consume or produce any bytes. The enclosing codec must
derive it from already-known protocol state and pass it to
ContextualCodec.
§Examples
use mcproto_types::contextual::Context;
let has_signature = true; // Derived from an earlier packet field.
let context = Context::new(has_signature);
assert!(context.is_present());
assert!(!Context::absent().is_present());Implementations§
Source§impl Context
impl Context
Sourcepub const fn new(present: bool) -> Self
pub const fn new(present: bool) -> Self
Creates a context from a presence condition determined by the enclosing protocol structure.
Sourcepub const fn absent() -> Self
pub const fn absent() -> Self
Creates context for a field that occupies zero bytes on the wire.
Sourcepub const fn is_present(&self) -> bool
pub const fn is_present(&self) -> bool
Returns whether the contextual field is present on the wire.
Trait Implementations§
impl Copy for Context
impl Eq for Context
impl StructuralPartialEq for Context
Auto Trait Implementations§
impl Freeze for Context
impl RefUnwindSafe for Context
impl Send for Context
impl Sync for Context
impl Unpin for Context
impl UnsafeUnpin for Context
impl UnwindSafe for Context
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