Skip to main content

EncodeContext

Struct EncodeContext 

Source
pub struct EncodeContext<'a, Value, Unit> { /* private fields */ }
Expand description

Context for one encode attempt inside a buffered encoder engine.

The context carries the current input value and output cursor. The hook decides whether the value can be consumed with the visible output capacity and reports that decision through crate::EncodeOutcome.

§Type Parameters

  • Value: Logical input value type.
  • Unit: Encoded output unit type.

Implementations§

Source§

impl<'a, Value, Unit> EncodeContext<'a, Value, Unit>

Source

pub fn new( input_value: &'a Value, input_index: usize, output: &'a mut [Unit], output_index: usize, ) -> Self

Creates an encode context.

§Parameters
  • input_value: Borrowed input value being encoded.
  • input_index: Absolute input index of input_value.
  • output: Complete output unit slice visible to the encoder.
  • output_index: Start position in output where writing begins.
§Returns

Returns an encode context.

Source

pub fn input_value(&self) -> &Value

Returns the input value being encoded.

§Returns

Returns a shared reference to the current input value.

Source

pub fn input_index(&self) -> usize

Returns the absolute input index of the current value.

§Returns

Returns the absolute input index.

Source

pub fn output(&mut self) -> &mut [Unit]

Returns the complete output unit slice visible to the encoder.

§Returns

Returns the output slice.

Source

pub fn output_index(&self) -> usize

Returns the start position in the output slice where writing begins.

§Returns

Returns the absolute output index.

Source

pub fn available_output(&self) -> usize

Returns writable output units from the current output index.

§Returns

Returns output capacity visible to this encode attempt.

Source

pub fn into_parts(self) -> (&'a Value, usize, &'a mut [Unit], usize)

Consumes the context and returns all parts.

Use this when you need simultaneous access to the input value reference and the mutable output slice, since Rust’s borrow checker disallows taking &self and &mut self in the same expression.

§Returns

Returns (input_value, input_index, output, output_index).

Trait Implementations§

Source§

impl<'a, Value: Debug, Unit: Debug> Debug for EncodeContext<'a, Value, Unit>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, Value, Unit> !UnwindSafe for EncodeContext<'a, Value, Unit>

§

impl<'a, Value, Unit> Freeze for EncodeContext<'a, Value, Unit>

§

impl<'a, Value, Unit> RefUnwindSafe for EncodeContext<'a, Value, Unit>
where Value: RefUnwindSafe, Unit: RefUnwindSafe,

§

impl<'a, Value, Unit> Send for EncodeContext<'a, Value, Unit>
where Value: Sync, Unit: Send,

§

impl<'a, Value, Unit> Sync for EncodeContext<'a, Value, Unit>
where Value: Sync, Unit: Sync,

§

impl<'a, Value, Unit> Unpin for EncodeContext<'a, Value, Unit>

§

impl<'a, Value, Unit> UnsafeUnpin for EncodeContext<'a, Value, Unit>

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.