pub struct AsyncTranscodeEncodeOutput<O>{ /* private fields */ }Expand description
Buffers asynchronous transcoder output while preserving pending units.
This adapter is the asynchronous counterpart to
super::TranscodeEncodeOutput. It owns the unit-level buffer, so a
future cancelled while the wrapped output is pending retains every unit
that the transcoder has already produced. Each transcode operation returns
after exactly one encoder invocation, so its progress is the explicit
source-consumption commit boundary.
§Type Parameters
O- Wrapped asynchronous unit output.
§Examples
use qubit_codec::AsyncTranscodeEncodeOutput;
use qubit_io::AsyncOutput;
fn make_output<O: AsyncOutput<Item = u8>>(inner: O) -> AsyncTranscodeEncodeOutput<O> {
AsyncTranscodeEncodeOutput::new(inner)
}Implementations§
Source§impl<O> AsyncTranscodeEncodeOutput<O>
impl<O> AsyncTranscodeEncodeOutput<O>
Sourcepub fn with_capacity(inner: O, capacity: usize) -> Self
pub fn with_capacity(inner: O, capacity: usize) -> Self
Sourcepub fn try_with_capacity(
inner: O,
capacity: usize,
) -> Result<Self, TryReserveError>
pub fn try_with_capacity( inner: O, capacity: usize, ) -> Result<Self, TryReserveError>
Tries to create an adapter with at least capacity buffered units.
§Errors
Returns an allocation error when the internal unit buffer cannot be allocated.
Sourcepub const fn inner(&self) -> &O
pub const fn inner(&self) -> &O
Returns a shared reference to the wrapped asynchronous output.
§Returns
Returns the wrapped output. Units can still be pending in this adapter.
Sourcepub fn inner_mut(&mut self) -> &mut O
pub fn inner_mut(&mut self) -> &mut O
Returns a mutable reference to the wrapped asynchronous output.
Pending adapter units are not automatically delivered before direct
output operations. Call Self::flush_async first when ordering with
previously transcoded data matters.
§Returns
Returns the wrapped output.
Sourcepub const fn pending_len(&self) -> usize
pub const fn pending_len(&self) -> usize
Returns the number of units retained pending delivery.
§Returns
Returns the length of the pending unit window.
Sourcepub fn into_parts(self) -> (O, Buffer<O::Item>)
pub fn into_parts(self) -> (O, Buffer<O::Item>)
Consumes this adapter without flushing the wrapped output.
This method performs no asynchronous I/O. The returned buffer holds units that must be delivered before the logical stream can continue.
§Returns
Returns the wrapped output and its pending unit buffer.
Source§impl<O> AsyncTranscodeEncodeOutput<O>
impl<O> AsyncTranscodeEncodeOutput<O>
Sourcepub async fn flush_async(&mut self) -> Result<()>
pub async fn flush_async(&mut self) -> Result<()>
Flushes pending transcoded units and the wrapped asynchronous output.
§Errors
Returns output-delivery or flush errors from the wrapped output. A failed delivery retains every unit that was not accepted.
Sourcepub async fn drain_async(&mut self) -> Result<()>
pub async fn drain_async(&mut self) -> Result<()>
Delivers pending transcoded units without flushing the wrapped output.
§Errors
Returns output-delivery errors from the wrapped output. A failed delivery retains every unit that was not accepted.
Sourcepub async fn reset_async<E, M, Value>(
&mut self,
encoder: &mut E,
map_error: &mut M,
) -> Result<()>
pub async fn reset_async<E, M, Value>( &mut self, encoder: &mut E, map_error: &mut M, ) -> Result<()>
Runs encoder reset and buffers its stream-prefix units.
§Parameters
encoder- Streaming encoder whose lifecycle is being started.map_error- Maps transcoder errors into I/O errors.
§Errors
Returns capacity planning, output delivery, allocation, or mapped reset errors. Pending units remain retained if asynchronous delivery fails.
§Panics
Panics when encoder writes more units than its declared reset bound.
Sourcepub fn poll_transcode<E, M, Value>(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
encoder: &mut E,
map_error: &mut M,
input: &[Value],
input_index: usize,
count: usize,
) -> Poll<Result<TranscodeProgress>>
pub fn poll_transcode<E, M, Value>( self: Pin<&mut Self>, cx: &mut Context<'_>, encoder: &mut E, map_error: &mut M, input: &[Value], input_index: usize, count: usize, ) -> Poll<Result<TranscodeProgress>>
Polls one cancellation-safe encoder operation.
The adapter may first deliver previously pending output to make a
conservative spare range available. Once it invokes encoder, it
advances the produced units and returns immediately without another
poll. The returned TranscodeProgress is therefore the exact source
range committed by this call.
§Parameters
encoder- Streaming encoder used for the conversion.map_error- Maps transcoder errors into I/O errors.input- Source values.input_index- First source value to transcode.count- Number of source values available frominput_index.
§Returns
Returns one validated encoder progress report.
§Errors
Returns invalid input ranges, output delivery, allocation, contract, or mapped transcoder errors. Pending units remain retained after a failed asynchronous delivery.
Sourcepub async fn transcode_async<E, M, Value>(
&mut self,
encoder: &mut E,
map_error: &mut M,
input: &[Value],
input_index: usize,
count: usize,
) -> Result<TranscodeProgress>
pub async fn transcode_async<E, M, Value>( &mut self, encoder: &mut E, map_error: &mut M, input: &[Value], input_index: usize, count: usize, ) -> Result<TranscodeProgress>
Transcodes one cancellation-safe progress step into the retained buffer.
This is the async wrapper for Self::poll_transcode. It returns after
one encoder invocation; callers that need to consume a whole source
range must advance the source index by TranscodeProgress::read and
call it again.
Sourcepub async fn finish_async<E, M, Value>(
&mut self,
encoder: &mut E,
map_error: &mut M,
) -> Result<()>
pub async fn finish_async<E, M, Value>( &mut self, encoder: &mut E, map_error: &mut M, ) -> Result<()>
Finishes the encoder and retains its final output for delivery.
§Parameters
encoder- Streaming encoder whose lifecycle is being finished.map_error- Maps transcoder errors into I/O errors.
§Errors
Returns capacity planning, allocation, or mapped finish errors. Call
Self::flush_async after this method to deliver final units. Keeping
finalization separate from delivery lets a caller record the completed
lifecycle before any later suspension point.
§Panics
Panics when encoder writes more units than its declared finish bound.