pub struct TranscodeProgress { /* private fields */ }Expand description
Counts how much work a crate::Transcoder completed before
returning.
§Examples
use qubit_codec::{TranscodeProgress, TranscodeStatus};
let progress = TranscodeProgress::complete(3, 6);
assert_eq!(progress.read(), 3);
assert_eq!(progress.written(), 6);
assert!(matches!(progress.status(), TranscodeStatus::Complete));Implementations§
Source§impl TranscodeProgress
impl TranscodeProgress
Sourcepub const fn new(status: TranscodeStatus, read: usize, written: usize) -> Self
pub const fn new(status: TranscodeStatus, read: usize, written: usize) -> Self
Sourcepub const fn complete(read: usize, written: usize) -> Self
pub const fn complete(read: usize, written: usize) -> Self
Creates a completed progress value.
§Parameters
read: Number of consumed input units.written: Number of produced output units.
§Returns
Returns a progress value whose status is TranscodeStatus::Complete.
Sourcepub const fn need_input(
required: NonZeroUsize,
read: usize,
written: usize,
) -> Self
pub const fn need_input( required: NonZeroUsize, read: usize, written: usize, ) -> Self
Creates progress that stopped because more input is needed.
§Parameters
required: Current minimum total input units required before retrying from the current input position. A later retry may raise this lower bound.read: Number of consumed input units.written: Number of produced output units.
§Returns
Returns a progress value with TranscodeStatus::NeedInput.
Sourcepub const fn need_output(
required: NonZeroUsize,
read: usize,
written: usize,
) -> Self
pub const fn need_output( required: NonZeroUsize, read: usize, written: usize, ) -> Self
Creates progress that stopped because more output capacity is needed.
§Parameters
required: Total output units required from the current output position.read: Number of consumed input units.written: Number of produced output units.
§Returns
Returns a progress value with TranscodeStatus::NeedOutput.
Sourcepub const fn status(self) -> TranscodeStatus
pub const fn status(self) -> TranscodeStatus
Sourcepub const fn is_complete(self) -> bool
pub const fn is_complete(self) -> bool
Returns whether conversion consumed all currently supplied input.
§Returns
Returns true when the stored status is
TranscodeStatus::Complete.
Sourcepub const fn is_need_input(self) -> bool
pub const fn is_need_input(self) -> bool
Returns whether conversion stopped because more input is needed.
§Returns
Returns true when the stored status is
TranscodeStatus::NeedInput.
Sourcepub const fn is_need_output(self) -> bool
pub const fn is_need_output(self) -> bool
Returns whether conversion stopped because more output capacity is needed.
§Returns
Returns true when the stored status is
TranscodeStatus::NeedOutput.
Sourcepub const fn read(self) -> usize
pub const fn read(self) -> usize
Returns the number of input units consumed by the call.
§Returns
Returns a count relative to the input index passed to the conversion call.
Sourcepub const fn written(self) -> usize
pub const fn written(self) -> usize
Returns the number of output units written by the call.
§Returns
Returns a count relative to the output index passed to the conversion call.
Sourcepub fn validate(
&self,
input_index: usize,
available_input: usize,
output_index: usize,
available_output: usize,
) -> Result<(), TranscodeContractError>
pub fn validate( &self, input_index: usize, available_input: usize, output_index: usize, available_output: usize, ) -> Result<(), TranscodeContractError>
Validates this progress against the call bounds supplied to a transcoder.
Buffered drivers should call this before using Self::read or
Self::written to advance unchecked input or output cursors. The
method checks relative counters, unsatisfied NeedInput / NeedOutput
requirements, and the Complete invariant that all visible input was
consumed.
This is a contract checker, not a semantic recovery policy. It performs
the same validation in every build profile. Drivers that advance unsafe
cursors may convert failures into their own error type, while
convenience helpers may assert that validation succeeds. Custom
crate::Transcoder implementations must therefore return progress
that satisfies the documented contract in all builds.
§Parameters
input_index: Input index originally passed to the transcoder.available_input: Number of input units visible frominput_index.output_index: Output index originally passed to the transcoder.available_output: Number of output slots visible fromoutput_index.
§Returns
Returns Ok(()) when progress is internally consistent with the
supplied call bounds.
§Errors
Returns TranscodeContractError when a custom transcoder reports
counters or missing-capacity requirements that do not match the buffers
supplied by the caller.
Trait Implementations§
Source§impl Clone for TranscodeProgress
impl Clone for TranscodeProgress
Source§fn clone(&self) -> TranscodeProgress
fn clone(&self) -> TranscodeProgress
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more