Skip to main content

MutableStructEncoder

Struct MutableStructEncoder 

Source
pub struct MutableStructEncoder<'a> { /* private fields */ }
Expand description

Encoder for a @mutable struct that validates non-optional member completeness (XTypes 1.3 §7.4.1.2.3).

Before each member encode, member_id is recorded as “emitted”; at finish, every member ID listed in required_ids must have been emitted, otherwise EncodeError::MissingNonOptionalMember is returned.

Spec background: an EXTENSIBLE (final/appendable/mutable) encode MUST contain all non-optional members. This validator closes the encoder gap for @mutable, because with MUTABLE the EMHEADER order is not fixed and encoder bugs would otherwise pass silently.

Implementations§

Source§

impl<'a> MutableStructEncoder<'a>

Source

pub fn new(writer: &'a mut BufferWriter, required_ids: Vec<u32>) -> Self

New encoder. required_ids is the list of member IDs that, per spec, MUST all be emitted (= all non-optional members of the struct).

Source

pub fn encode_member<F>( &mut self, member_id: u32, must_understand: bool, body: F, ) -> Result<(), EncodeError>
where F: FnOnce(&mut BufferWriter) -> Result<(), EncodeError>,

Encode a member. Behaves like encode_mutable_member, plus tracking of the emitted ID.

§Errors

Same as encode_mutable_member.

Source

pub fn encode_member_lc<F>( &mut self, member_id: u32, must_understand: bool, lc: LengthCode, body: F, ) -> Result<(), EncodeError>
where F: FnOnce(&mut BufferWriter) -> Result<(), EncodeError>,

Member with an explicit length code.

§Errors

Same as encode_mutable_member_lc.

Source

pub fn finish(self) -> Result<(), EncodeError>

Finishes the mutable sequence and checks that every member ID listed in required_ids was emitted.

§Errors

MissingNonOptionalMember { member_id } with the first missing ID (deterministic in the order of the required_ids list).

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.