pub trait CodecValueExt: Codec {
// Provided methods
fn max_encode_value_units(&self) -> Result<usize, CapacityError> { ... }
fn encode_value_with_reset(
&mut self,
value: &Self::Value,
output: &mut [Self::Unit],
output_index: usize,
) -> Result<usize, CodecEncodeError<Self::EncodeError>> { ... }
fn decode_value_with_flush(
&mut self,
input: &[Self::Unit],
input_index: usize,
flush_output: &mut [Self::Value],
flush_output_index: usize,
) -> Result<(Self::Value, NonZeroUsize, usize), CodecDecodeError<Self::DecodeError>> { ... }
fn decode_exact_value_with_flush(
&mut self,
input: &[Self::Unit],
flush_output: &mut [Self::Value],
flush_output_index: usize,
) -> Result<(Self::Value, usize), CodecDecodeError<Self::DecodeError>> { ... }
}Expand description
Extension trait for checked one-value codec operations.
CodecValueExt keeps convenience operations out of the low-level
Codec contract while still making them available to all codec
implementations. The methods compose primitive reset, encode, decode, and
flush hooks with capacity checks and adapter-level error wrapping.
Provided Methods§
Sourcefn max_encode_value_units(&self) -> Result<usize, CapacityError>
fn max_encode_value_units(&self) -> Result<usize, CapacityError>
Returns the maximum unit count emitted by one reset-prefixed value encode.
This is the checked sum of
Codec::max_encode_reset_units and
Codec::max_units_per_value. It is useful for callers that want to
reuse scratch storage for repeated one-value encodes.
§Returns
Returns the maximum reset-plus-value output length.
§Errors
Returns CapacityError::OutputLengthOverflow when the sum cannot be
represented as usize.
Sourcefn encode_value_with_reset(
&mut self,
value: &Self::Value,
output: &mut [Self::Unit],
output_index: usize,
) -> Result<usize, CodecEncodeError<Self::EncodeError>>
fn encode_value_with_reset( &mut self, value: &Self::Value, output: &mut [Self::Unit], output_index: usize, ) -> Result<usize, CodecEncodeError<Self::EncodeError>>
Encodes one value after emitting reset output into a caller buffer.
The method validates the output index and the combined reset-plus-value capacity before calling the unchecked codec hooks. It is a convenience wrapper for code paths that need one complete value and want to reuse caller-owned storage.
§Parameters
value: Value to encode.output: Destination unit buffer.output_index: Start index inoutput.
§Returns
Returns the total number of reset and value units written.
§Errors
Returns CodecEncodeError::UnencodableValue when value is outside
this codec’s encodable domain,
CodecEncodeError::InvalidOutputIndex when output_index is outside
output, CodecEncodeError::InsufficientOutput when the writable
suffix cannot hold the reset output plus exact encoded value width,
CodecEncodeError::OutputLengthOverflow when the bound overflows, or
CodecEncodeError::Encode when reset or value encoding fails.
§Panics
Panics when the codec writes or reports more units than its declared reset or value bound.
Sourcefn decode_value_with_flush(
&mut self,
input: &[Self::Unit],
input_index: usize,
flush_output: &mut [Self::Value],
flush_output_index: usize,
) -> Result<(Self::Value, NonZeroUsize, usize), CodecDecodeError<Self::DecodeError>>
fn decode_value_with_flush( &mut self, input: &[Self::Unit], input_index: usize, flush_output: &mut [Self::Value], flush_output_index: usize, ) -> Result<(Self::Value, NonZeroUsize, usize), CodecDecodeError<Self::DecodeError>>
Decodes one value and flushes decode-side state into caller storage.
The method validates input and flush-output bounds before entering the
unchecked codec hooks. It returns the decoded value, the consumed input
count, and the number of flushed values written to flush_output.
§Parameters
input: Source unit buffer.input_index: Start index ininput.flush_output: Destination value buffer for decode-flush output.flush_output_index: Start index inflush_output.
§Returns
Returns (value, consumed, flushed).
§Errors
Returns CodecDecodeError::InvalidInputIndex when input_index is
outside input, CodecDecodeError::Incomplete when fewer than
Codec::min_units_per_value units are readable,
CodecDecodeError::InvalidOutputIndex or
CodecDecodeError::InsufficientOutput when flush output cannot hold
Codec::max_decode_flush_values, or CodecDecodeError::Decode
when decoding or flushing fails.
§Panics
Panics when the codec consumes beyond available input or flushes more values than its declared bound.
Sourcefn decode_exact_value_with_flush(
&mut self,
input: &[Self::Unit],
flush_output: &mut [Self::Value],
flush_output_index: usize,
) -> Result<(Self::Value, usize), CodecDecodeError<Self::DecodeError>>
fn decode_exact_value_with_flush( &mut self, input: &[Self::Unit], flush_output: &mut [Self::Value], flush_output_index: usize, ) -> Result<(Self::Value, usize), CodecDecodeError<Self::DecodeError>>
Decodes exactly one value and then flushes decode-side state.
Unlike decode_value_with_flush, this
helper requires the supplied input slice to contain exactly one encoded
value. It validates trailing input before calling
Codec::decode_flush, preserving whole-value decoder semantics while
still centralizing flush scratch-buffer handling.
§Parameters
input: Source units for exactly one encoded value.flush_output: Destination value buffer for decode-flush output.flush_output_index: Start index inflush_output.
§Returns
Returns (value, flushed).
§Errors
Returns CodecDecodeError::Incomplete when fewer than
Codec::min_units_per_value units are available,
CodecDecodeError::TrailingInput when decode succeeds but leaves
extra units, output-capacity errors for invalid flush storage, or
CodecDecodeError::Decode when decoding or flushing fails.
§Panics
Panics when the codec consumes beyond available input or flushes more values than its declared bound.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".