pub struct TranscodeDecodeInput<I>{ /* private fields */ }Expand description
Decodes an Input unit stream into an Input value stream.
This type owns only the unit-level qubit_io::BufferedInput. Callers pass
a streaming Transcoder and error mapper to each decode operation, which
lets one buffered input drive different decoders without nesting buffers or
storing decoder-specific state in the buffer owner.
§Type Parameters
I- Wrapped unit input.
§Examples
use core::convert::Infallible;
use core::num::NonZeroUsize;
use std::io::Cursor;
use qubit_codec::Codec;
use qubit_codec::DecodeFailure;
use qubit_codec::TranscodeDecodeInput;
struct Identity;
impl Codec for Identity {
type Value = u8;
type Unit = u8;
type DecodeError = Infallible;
type EncodeError = Infallible;
const MIN_UNITS_PER_VALUE: usize = 1;
const MAX_DECODE_UNITS_PER_VALUE: usize = 1;
const MAX_ENCODE_UNITS_PER_VALUE: usize = 1;
unsafe fn decode(&mut self, input: &[u8], index: usize)
-> Result<(u8, NonZeroUsize), DecodeFailure<Infallible>> {
Ok((input[index], NonZeroUsize::MIN))
}
unsafe fn encode(&mut self, value: &u8, output: &mut [u8], index: usize)
-> Result<usize, Infallible> {
output[index] = *value;
Ok(1)
}
}
let mut input = TranscodeDecodeInput::with_capacity(Cursor::new(vec![42_u8]), 8);
assert!(input.fill_until(1).expect("refilling the cursor input should succeed"));
assert_eq!(input.unread(), &[42]);
let value = input.read_decoded_with(&mut Identity, |error| match error {})?;
assert_eq!(value, 42);read_decoded_with reads one complete value and owns its strict
single-value lifecycle; use the step methods when the caller needs to
coordinate streaming input and output itself.
Implementations§
Source§impl<I> TranscodeDecodeInput<I>
impl<I> TranscodeDecodeInput<I>
Sourcepub fn with_capacity(inner: I, capacity: usize) -> Self
pub fn with_capacity(inner: I, capacity: usize) -> Self
Creates a decoder input with a unit buffer of at least capacity.
§Parameters
inner- Unit input read by this adapter.capacity- Requested internal unit buffer capacity.
§Returns
A new buffered decoder input.
§Panics
Panics if I::Item::default() panics or the requested capacity exceeds
the supported allocation size.
Sourcepub fn try_with_capacity(
inner: I,
capacity: usize,
) -> StdResult<Self, TryReserveError>
pub fn try_with_capacity( inner: I, capacity: usize, ) -> StdResult<Self, TryReserveError>
Creates a decoder input with a unit buffer of at least capacity.
§Parameters
inner- Unit input read by this adapter.capacity- Requested internal unit buffer capacity.
§Returns
Returns a buffered adapter owning inner with at least the requested
capacity.
§Errors
Returns an allocation error when the requested buffer cannot be allocated.
§Panics
Panics if I::Item::default() panics while initializing the buffer.
Sourcepub const fn inner(&self) -> &I
pub const fn inner(&self) -> &I
Returns a shared reference to the wrapped unit input.
The wrapped input can be physically positioned after units that remain unread in this adapter’s internal buffer.
§Returns
A shared reference to the wrapped unit input.
Sourcepub fn unread_len(&self) -> usize
pub fn unread_len(&self) -> usize
Returns the number of unread units currently buffered.
§Returns
The number of unread units in the internal buffer.
Sourcepub fn unread(&self) -> &[I::Item]
pub fn unread(&self) -> &[I::Item]
Returns the currently buffered unread units.
§Returns
Returns a shared slice over the unread portion of the internal unit buffer. The slice is valid until this adapter is mutated.
Sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns the internal unit buffer capacity.
§Returns
The maximum number of units retained in the internal buffer.
Sourcepub fn fill_until(&mut self, count: usize) -> Result<bool>
pub fn fill_until(&mut self, count: usize) -> Result<bool>
Refills the internal buffer until at least count unread units are
available.
§Parameters
count- Minimum number of unread units required.
§Returns
Returns true when at least count units are buffered; false if EOF
prevents reaching that count. Buffered units remain available in either
case.
§Errors
Returns allocation errors mapped to ErrorKind::OutOfMemory, or I/O
errors from the wrapped input while refilling.
Sourcepub fn transcode_step<D, M, Value>(
&mut self,
decoder: &mut D,
map_error: &mut M,
output: &mut [Value],
output_index: usize,
count: usize,
) -> Result<Option<TranscodeProgress>>
pub fn transcode_step<D, M, Value>( &mut self, decoder: &mut D, map_error: &mut M, output: &mut [Value], output_index: usize, count: usize, ) -> Result<Option<TranscodeProgress>>
Performs one decode step and preserves the transcoder stop status.
None means that the wrapped input reached EOF with no buffered units.
Consumed input is committed before this method returns. Callers can use
the returned TranscodeProgress to distinguish NeedOutput from an
incomplete input tail without guessing from the unread buffer alone.
§Type Parameters
D: Streaming decoder accepting the source unit type.M: Mapper from decoder errors to I/O errors.Value: Decoded destination value type.
§Parameters
decoder: Decoder for the current logical stream.map_error: Mapper invoked for decoder errors.output: Destination value storage.output_index: Start of the writable range.count: Maximum number of destination values available.
§Returns
Returns Some validated progress after a decode step, or None at EOF
with no buffered units. A zero count returns Some zero progress.
§Errors
Returns invalid output-range or progress errors, input/refill errors,
or decoder errors translated by map_error.
A successful validated progress commits its read() count. If decoding
or progress validation fails, this call does not consume the unread
range. The decoder and destination may already have changed; neither is
rolled back, and no complete progress report is available. A refill
performed before the failure is not rolled back at the wrapped input.
Do not replay the original input unless the decoder defines an explicit
recovery protocol.
Sourcepub fn transcode_eof_step<D, M, Value>(
&mut self,
decoder: &mut D,
map_error: &mut M,
output: &mut [Value],
output_index: usize,
count: usize,
) -> Result<TranscodeProgress>
pub fn transcode_eof_step<D, M, Value>( &mut self, decoder: &mut D, map_error: &mut M, output: &mut [Value], output_index: usize, count: usize, ) -> Result<TranscodeProgress>
Performs one decode step after the caller has established EOF.
This method does not read from the wrapped input. It passes the current
unread buffer to Transcoder::transcode_eof, validates the returned
progress, and commits consumed source units before returning.
§Type Parameters
D: Streaming decoder accepting the source unit type.M: Mapper from decoder errors to I/O errors.Value: Decoded destination value type.
§Parameters
decoder: Decoder for the current logical stream.map_error: Mapper invoked for decoder errors.output: Destination value storage.output_index: Start of the writable range.count: Maximum number of destination values available.
§Returns
Returns validated EOF progress. A zero output count returns zero
progress without calling the decoder; an empty input is still passed to
transcode_eof so decoders can handle EOF with retained state.
§Errors
Returns invalid output-range errors, decoder errors mapped by
map_error, or InvalidData if the decoder requests more input after
EOF. Invalid progress does not commit source consumption, but decoder
state and caller-owned output are not rolled back.
Sourcepub fn consume(&mut self, count: usize)
pub fn consume(&mut self, count: usize)
Consumes unread units from the current buffer window.
§Parameters
count- Number of unread units to discard.
§Panics
Panics when count exceeds Self::unread_len.
Sourcepub unsafe fn copy_unread_to(
&self,
output: &mut [I::Item],
output_index: usize,
count: usize,
)
pub unsafe fn copy_unread_to( &self, output: &mut [I::Item], output_index: usize, count: usize, )
Copies unread units into an indexed output range without consuming them.
§Parameters
output- Destination storage that receives a copy of unread units.output_index- Start index insideoutput.count- Number of unread units to copy.
§Safety
The caller must guarantee that output_index..output_index + count is
a valid range inside output, that the addition does not overflow, that
count <= self.unread_len(), and that the destination range does not
overlap with the unread units stored inside this buffer.
Sourcepub fn into_parts(self) -> (I, Buffer<I::Item>)
pub fn into_parts(self) -> (I, Buffer<I::Item>)
Consumes this adapter and returns its parts.
§Returns
The wrapped input and the buffer holding unread units.
Sourcepub unsafe fn read_unchecked(
&mut self,
output: &mut [I::Item],
output_index: usize,
count: usize,
) -> Result<usize>
pub unsafe fn read_unchecked( &mut self, output: &mut [I::Item], output_index: usize, count: usize, ) -> Result<usize>
Reads buffered units into an indexed output range.
§Parameters
output- Destination unit storage.output_index- Start index insideoutput.count- Maximum number of units to read.
§Returns
The number of units copied into output.
§Errors
Returns input or buffer validation errors from the wrapped
qubit_io::BufferedInput.
§Panics
Debug builds panic if the destination range violates the safety contract.
§Safety
The caller must guarantee that output_index..output_index + count is
a valid range inside output and that the addition does not overflow.
Sourcepub fn read_decoded_with<C, M>(
&mut self,
codec: &mut C,
map_error: M,
) -> Result<C::Value>
pub fn read_decoded_with<C, M>( &mut self, codec: &mut C, map_error: M, ) -> Result<C::Value>
Decodes one codec value from the buffered unit input.
This strict convenience method supports codecs whose decode reset and
finish phases do not emit values. Use
Self::read_decoded_lifecycle_with when those phases have output.
§Type Parameters
C: Codec accepting the wrapped input’s unit type.M: Mapper from codec decode errors to I/O errors.
§Parameters
codec- Codec used for this single-value decode.map_error- Mapper for codec-domain invalid-input errors.
§Returns
Returns one decoded codec value.
§Errors
Returns ErrorKind::Unsupported before invoking the codec or reading
input when reset or finish may emit values. Otherwise, returns I/O
errors from the wrapped input, UnexpectedEof when EOF occurs before a
complete value is available, InvalidData when the codec reports an
impossible incomplete state, or a mapped codec-domain error for reset,
invalid input, or finish failures. Each mapped error owns a
TranscodeDomainError identifying the phase; main decode errors use
index 0, the start of this single-value input window. The mapper’s
error remains the wrapper source, preserving its kind and payload.
This operation is not transactional. A successful main decode consumes
its source units before codec finalization. If finalization fails, the
decoded value is not returned and the consumed input is not restored.
A later read must not be treated as a retry of that value. Truncated
input at EOF is consumed before reporting the error. Invalid-input
consumption follows the codec’s validated consumption hint. Codec
state is not rolled back. The Unsupported preflight error above is
returned before invoking the codec or reading input.
§Panics
Panics when the codec reports more reset or finish values than its declared bounds.
Sourcepub fn read_decoded_lifecycle_with<C, M>(
&mut self,
codec: &mut C,
map_error: M,
) -> Result<DecodeLifecycleOutput<C::Value>>
pub fn read_decoded_lifecycle_with<C, M>( &mut self, codec: &mut C, map_error: M, ) -> Result<DecodeLifecycleOutput<C::Value>>
Decodes one complete codec lifecycle and preserves every output phase.
The method allocates independent storage for values emitted by
decode_reset and decode_finish, so neither phase can overwrite the
other.
§Type Parameters
C: Codec accepting the wrapped input’s unit type.M: Mapper from codec decode errors to I/O errors.
§Parameters
codec: Codec used to decode one complete lifecycle.map_error: Maps codec decode errors to I/O errors.
§Returns
Returns reset output, the main decoded value, and finish output.
§Errors
Returns I/O errors from the wrapped input, UnexpectedEof when EOF
occurs before a complete value is available, InvalidData when the
codec reports an impossible incomplete state, or a mapped codec-domain
error for reset, invalid input, or finish failures. Each mapped error
owns a TranscodeDomainError identifying the phase; main decode
errors use index 0, the start of this input window. The mapper’s error
remains the wrapper source, preserving its kind and payload.
Returns OutOfMemory when lifecycle output storage cannot be reserved.
This operation is not transactional. A successful main decode consumes its source units before codec finalization. If finalization fails, the decoded value is not returned and the consumed input is not restored. A later read must not be treated as a retry of that value. Truncated input at EOF is consumed before reporting the error. Invalid-input consumption follows the codec’s validated consumption hint. Codec state is not rolled back.
§Panics
Panics when the codec reports more reset or finish values than its declared bounds.
Sourcepub fn read_decoded_lifecycle_with_scratch<C, M>(
&mut self,
codec: &mut C,
reset_output: &mut [C::Value],
finish_output: &mut [C::Value],
map_error: M,
) -> Result<DecodeLifecycleProgress<C::Value>>
pub fn read_decoded_lifecycle_with_scratch<C, M>( &mut self, codec: &mut C, reset_output: &mut [C::Value], finish_output: &mut [C::Value], map_error: M, ) -> Result<DecodeLifecycleProgress<C::Value>>
Decodes one complete codec lifecycle into separate caller storage.
§Type Parameters
C: Codec accepting the wrapped input’s unit type.M: Mapper from codec decode errors to I/O errors.
§Parameters
codec: Codec used to decode one complete lifecycle.reset_output: Reusable storage for values emitted byCodec::decode_reset.finish_output: Reusable storage for values emitted byCodec::decode_finish.map_error: Maps codec decode errors to I/O errors.
§Returns
Returns the main decoded value and the initialized lengths of both lifecycle output buffers.
§Errors
Returns ErrorKind::InvalidInput when either output buffer is shorter
than the corresponding codec bound. Returns I/O errors from the wrapped
input, UnexpectedEof when EOF occurs before a complete value is
available, InvalidData when the codec reports an impossible
incomplete state, or a mapped codec-domain error for reset, invalid
input, or finish failures. Each mapped error owns a
TranscodeDomainError identifying the phase; main decode errors use
index 0, the start of this input window. The mapper’s error remains
the wrapper source, preserving its kind and payload.
This operation is not transactional. A successful main decode consumes its source units before codec finalization. If finalization fails, the decoded value is not returned and the consumed input is not restored. A later read must not be treated as a retry of that value. Truncated input at EOF is consumed before reporting the error. Invalid-input consumption follows the codec’s validated consumption hint. Codec state is not rolled back. A short scratch buffer is rejected before invoking the codec or reading input. Reset and finish output buffers may already have changed when an error is returned; the error carries no valid output lengths, so their full contents must not be treated as this operation’s successful output. Recovery of codec state after an error is codec-specific, and consumed input is never restored.
§Panics
Panics when the codec reports more reset or finish values than its declared bounds.
Sourcepub fn reset<D, M, Value>(
&self,
decoder: &mut D,
map_error: &mut M,
output: &mut [Value],
output_index: usize,
count: usize,
) -> Result<usize>
pub fn reset<D, M, Value>( &self, decoder: &mut D, map_error: &mut M, output: &mut [Value], output_index: usize, count: usize, ) -> Result<usize>
Runs decoder reset into an indexed output range.
This method does not read or consume buffered input units.
§Type Parameters
D: Streaming decoder accepting the source unit type.M: Mapper from decoder errors to I/O errors.Value: Decoded destination value type.
§Parameters
decoder: Decoder for the current logical stream.map_error: Mapper invoked for decoder errors.output: Destination value storage.output_index: Start of the writable range.count: Maximum number of destination values available.
§Returns
Returns the number of reset values initialized in the requested range.
§Errors
Returns invalid output ranges, insufficient declared output capacity,
capacity errors, or reset errors mapped by map_error.
§Panics
Panics when the decoder reports writing more values than its declared reset bound.
Sourcepub fn transcode<D, M, Value>(
&mut self,
decoder: &mut D,
map_error: &mut M,
output: &mut [Value],
output_index: usize,
count: usize,
) -> Result<usize>
pub fn transcode<D, M, Value>( &mut self, decoder: &mut D, map_error: &mut M, output: &mut [Value], output_index: usize, count: usize, ) -> Result<usize>
Decodes values into an indexed output range using a streaming
Transcoder.
§Type Parameters
D: Streaming decoder accepting the source unit type.M: Mapper from decoder errors to I/O errors.Value: Decoded destination value type.
§Parameters
decoder- Streaming decoder used for this operation.map_error- Function mapping transcode errors into I/O errors.output- Destination value storage.output_index- Start index insideoutput.count- Maximum number of values to write.
§Returns
The number of values written. When this method is driven through EOF
with output capacity remaining, it passes the retained tail—or an empty
input when no tail remains—to Transcoder::transcode_eof before
returning.
A short return, including zero, may mean the decoder requires a larger
contiguous output range. It does not prove conversion is complete. Use
Self::transcode_step and Self::transcode_eof_step when the stop
reason and required capacity must remain observable.
§Errors
Returns input errors, invalid output ranges, capacity errors from the
internal buffer, or transcode errors mapped by map_error.
This operation is not transactional. An error may be returned after
source units have been consumed and values have been written to
output. Progress is not rolled back, and the error does not report
the accumulated output length. Use transcode_step and commit each
successful progress result when previously decoded values must
remain observable after a later failure.
The method does not refill for later values once the requested output
range is full; the underlying input may still prefetch units beyond
that range during an earlier read. If EOF processing stops with
NeedOutput, the next batch call resumes EOF processing directly;
a short return, including zero, does not mean conversion is complete.
Use the step methods when the exact stop reason is needed. Explicitly
refilling new units, seeking, or switching to raw/single-value reads
changes the input context; callers remain responsible for the decoder
lifecycle when continuing after such a switch.
Sourcepub fn finish<D, M, Value>(
&self,
decoder: &mut D,
map_error: &mut M,
output: &mut [Value],
output_index: usize,
count: usize,
) -> Result<usize>
pub fn finish<D, M, Value>( &self, decoder: &mut D, map_error: &mut M, output: &mut [Value], output_index: usize, count: usize, ) -> Result<usize>
Finishes a streaming decoder into an indexed output range.
§Type Parameters
D: Streaming decoder accepting the source unit type.M: Mapper from decoder errors to I/O errors.Value: Decoded destination value type.
§Parameters
decoder- Streaming decoder whose final output is being collected.map_error- Function mapping transcode errors into I/O errors.output- Destination value storage.output_index- Start index insideoutput.count- Maximum number of finish values to write.
§Returns
The number of values written by the decoder finish operation.
§Errors
Returns invalid output ranges, capacity errors, or transcode finalization errors mapped to I/O errors.
§Panics
Panics when the decoder reports writing more values than its
Transcoder::max_finish_output_len bound.
Source§impl<I> TranscodeDecodeInput<I>where
I: SeekableByteInput,
impl<I> TranscodeDecodeInput<I>where
I: SeekableByteInput,
Trait Implementations§
Source§impl<I> Debug for TranscodeDecodeInput<I>
impl<I> Debug for TranscodeDecodeInput<I>
Source§fn fmt(&self, formatter: &mut Formatter<'_>) -> FormatResult
fn fmt(&self, formatter: &mut Formatter<'_>) -> FormatResult
Source§impl<I> Read for TranscodeDecodeInput<I>where
I: ByteInput,
impl<I> Read for TranscodeDecodeInput<I>where
I: ByteInput,
1.36.0 · Source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
read, except that it reads into a slice of buffers. Read moreSource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector)1.0.0 · Source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
buf. Read more1.0.0 · Source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
buf. Read more1.6.0 · Source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf. Read moreSource§fn read_buf(&mut self, buf: BorrowedCursor<'_, u8>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_, u8>) -> Result<(), Error>
read_buf)Source§fn read_buf_exact(
&mut self,
cursor: BorrowedCursor<'_, u8>,
) -> Result<(), Error>
fn read_buf_exact( &mut self, cursor: BorrowedCursor<'_, u8>, ) -> Result<(), Error>
read_buf)cursor. Read more1.0.0 · Source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read. Read more1.0.0 · Source§fn chain<R>(self, next: R) -> Chain<Self, R> ⓘ
fn chain<R>(self, next: R) -> Chain<Self, R> ⓘ
1.0.0 · Source§fn take(self, limit: u64) -> Take<Self> ⓘwhere
Self: Sized,
fn take(self, limit: u64) -> Take<Self> ⓘwhere
Self: Sized,
limit bytes from it. Read moreSource§fn read_array<const N: usize>(&mut self) -> Result<[u8; N], Error>where
Self: Sized,
fn read_array<const N: usize>(&mut self) -> Result<[u8; N], Error>where
Self: Sized,
read_array)Source§impl<I> Seek for TranscodeDecodeInput<I>where
I: SeekableByteInput,
impl<I> Seek for TranscodeDecodeInput<I>where
I: SeekableByteInput,
1.55.0 · Source§fn rewind(&mut self) -> Result<(), Error>
fn rewind(&mut self) -> Result<(), Error>
Source§fn stream_len(&mut self) -> Result<u64, Error>
fn stream_len(&mut self) -> Result<u64, Error>
seek_stream_len)Auto Trait Implementations§
impl<I> Forget for TranscodeDecodeInput<I>
impl<I> Freeze for TranscodeDecodeInput<I>
impl<I> RefUnwindSafe for TranscodeDecodeInput<I>
impl<I> Send for TranscodeDecodeInput<I>
impl<I> Sync for TranscodeDecodeInput<I>
impl<I> Unpin for TranscodeDecodeInput<I>
impl<I> UnsafeUnpin for TranscodeDecodeInput<I>
impl<I> UnwindSafe for TranscodeDecodeInput<I>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<T> ByteInput for T
Source§impl<R> Input for R
impl<R> Input for R
Source§unsafe fn read_unchecked(
&mut self,
output: &mut [u8],
index: usize,
count: usize,
) -> Result<usize, Error>
unsafe fn read_unchecked( &mut self, output: &mut [u8], index: usize, count: usize, ) -> Result<usize, Error>
Reads bytes into a caller-validated indexed output range.
§Parameters
output: Destination byte slice.index: Start offset insideoutput.count: Maximum number of bytes to read.
§Returns
The number of bytes reported by the standard reader.
A successful call may read fewer than count bytes. A return value of
zero indicates that no bytes were read; for a nonempty request this
normally signals end of input. This method does not retry short reads.
§Errors
Returns the error reported by the standard reader.
§Panics
Panics in debug builds if the requested destination range does not fit.
§Safety
The caller must ensure that index through index plus count is a valid range inside output without overflowing.
Source§fn read(&mut self, output: &mut [<R as Input>::Item]) -> Result<usize, Error>
fn read(&mut self, output: &mut [<R as Input>::Item]) -> Result<usize, Error>
Reads bytes into the complete output slice.
§Parameters
output: Destination byte slice.
§Returns
The number of bytes read into output.
A successful call may fill only part of output; zero means no bytes
were read and normally signals end of input for a nonempty buffer. This
method does not retry short reads.
§Errors
Returns std::io::ErrorKind::InvalidData if the reader reports more
bytes than output holds, or the error reported by the standard reader.
Source§fn read_vectored(&mut self, buffers: &mut [&mut [u8]]) -> Result<usize, Error>
fn read_vectored(&mut self, buffers: &mut [&mut [u8]]) -> Result<usize, Error>
Reads from the buffers in order using the standard reader’s vectored method. A single descriptor uses stack storage; multiple descriptors may allocate descriptor storage, and the reader may allocate independently. Short progress and reader errors are returned without retrying or undoing underlying side effects.
§Parameters
buffers: Mutable byte buffers to fill in order.
§Returns
The number of bytes reported by the standard reader, up to the total
capacity of buffers.
§Errors
Returns std::io::ErrorKind::InvalidInput if the total buffer length
overflows, std::io::ErrorKind::OutOfMemory if multiple-descriptor
preparation fails before I/O, std::io::ErrorKind::InvalidData if
the reader reports more than the total capacity, or the error reported
by the standard reader.
Source§fn into_std_read(self) -> StdRead<Self> ⓘ
fn into_std_read(self) -> StdRead<Self> ⓘ
Source§fn is_buffered(&self) -> bool
fn is_buffered(&self) -> bool
Source§unsafe fn read_fully_unchecked(
&mut self,
output: &mut [Self::Item],
index: usize,
count: usize,
) -> Result<usize, Error>
unsafe fn read_fully_unchecked( &mut self, output: &mut [Self::Item], index: usize, count: usize, ) -> Result<usize, Error>
Source§impl<T> ReadExt for T
impl<T> ReadExt for T
Source§unsafe fn read_unchecked(
&mut self,
buffer: &mut [u8],
start_index: usize,
count: usize,
) -> Result<usize, Error>
unsafe fn read_unchecked( &mut self, buffer: &mut [u8], start_index: usize, count: usize, ) -> Result<usize, Error>
Reads bytes from an unchecked range into a standard Read value.
§Parameters
buffer: Destination buffer.start_index: Start offset insidebuffer.count: Maximum number of bytes to read.
§Returns
The number of bytes read into the requested range.
§Errors
Returns the error reported by Read::read.
§Panics
Panics in debug builds if the requested output range does not fit.
§Safety
The caller must guarantee that start_index..start_index + count is
valid inside buffer and that the addition does not overflow.
Source§unsafe fn read_exact_or_eof_unchecked(
&mut self,
buffer: &mut [u8],
start_index: usize,
count: usize,
) -> Result<usize, Error>
unsafe fn read_exact_or_eof_unchecked( &mut self, buffer: &mut [u8], start_index: usize, count: usize, ) -> Result<usize, Error>
Reads an unchecked range until it is full or EOF is reached.
§Parameters
buffer: Destination buffer.start_index: Start offset insidebuffer.count: Number of bytes to try to read.
§Returns
The number of bytes read into the requested range.
§Errors
Returns the first non-interrupted read error, or
std::io::ErrorKind::InvalidData if the reader reports more bytes
than requested.
§Panics
Panics in debug builds if the requested output range does not fit.
§Safety
The caller must guarantee that start_index..start_index + count is
valid inside buffer and that the addition does not overflow.
Source§unsafe fn read_exact_unchecked(
&mut self,
buffer: &mut [u8],
start_index: usize,
count: usize,
) -> Result<(), Error>
unsafe fn read_exact_unchecked( &mut self, buffer: &mut [u8], start_index: usize, count: usize, ) -> Result<(), Error>
Reads exactly the requested unchecked range.
§Parameters
buffer: Destination buffer.start_index: Start offset insidebuffer.count: Number of bytes to read.
§Returns
Ok(()) after the requested range has been filled.
§Errors
Returns the error reported by Read::read_exact.
§Panics
Panics in debug builds if the requested output range does not fit.
§Safety
The caller must guarantee that start_index..start_index + count is
valid inside buffer and that the addition does not overflow.
Source§fn read_exact_or_eof(&mut self, buffer: &mut [u8]) -> Result<usize, Error>
fn read_exact_or_eof(&mut self, buffer: &mut [u8]) -> Result<usize, Error>
Reads the destination until it is full or EOF is reached.
§Parameters
buffer: Destination buffer.
§Returns
The number of bytes read into buffer.
§Errors
Returns the first non-interrupted read error, or
std::io::ErrorKind::InvalidData if the reader reports more bytes
than requested.
Source§fn read_exact_array<const N: usize>(&mut self) -> Result<[u8; N], Error>
fn read_exact_array<const N: usize>(&mut self) -> Result<[u8; N], Error>
Reads exactly N bytes into an array.
§Type Parameters
N: Number of bytes in the returned array.
§Returns
An array containing exactly N bytes.
§Errors
Returns the error reported by Read::read_exact.
Source§fn read_exact_vec_limited(
&mut self,
len: usize,
max_len: usize,
) -> Result<Vec<u8>, Error>
fn read_exact_vec_limited( &mut self, len: usize, max_len: usize, ) -> Result<Vec<u8>, Error>
Reads an exactly sized vector within a configured limit.
§Parameters
len: Exact number of bytes to read.max_len: Maximum accepted exact read length.
§Returns
A vector containing exactly len bytes.
§Errors
Returns std::io::ErrorKind::OutOfMemory if the result vector cannot
be allocated, a read error, or std::io::ErrorKind::InvalidData
when len > max_len.
Source§fn read_exact_vec_limited_into(
&mut self,
output: &mut Vec<u8>,
len: usize,
max_len: usize,
) -> Result<(), Error>
fn read_exact_vec_limited_into( &mut self, output: &mut Vec<u8>, len: usize, max_len: usize, ) -> Result<(), Error>
Reads exactly len bytes and appends them to a vector.
§Parameters
output: Destination vector.len: Exact number of bytes to read.max_len: Maximum accepted exact read length.
§Returns
Ok(()) after exactly len bytes have been appended.
§Errors
Returns std::io::ErrorKind::OutOfMemory if output cannot grow, a
read error, std::io::ErrorKind::InvalidData when len > max_len, or std::io::ErrorKind::InvalidInput when `output.len()
- len` overflows.
Source§fn copy_to_at_most(
&mut self,
writer: &mut dyn Write,
max_bytes: u64,
) -> Result<u64, Error>
fn copy_to_at_most( &mut self, writer: &mut dyn Write, max_bytes: u64, ) -> Result<u64, Error>
Copies at most the requested number of bytes to a writer.
§Parameters
writer: Destination writer.max_bytes: Maximum number of bytes to copy.
§Returns
The number of bytes copied.
§Errors
Returns std::io::ErrorKind::OutOfMemory if the temporary copy buffer
cannot be allocated, or the first non-interrupted read error or
write error. Returns std::io::ErrorKind::InvalidData if the
reader reports more bytes than requested. Bytes from that invalid
read are not written; previously copied bytes are not rolled back.
Source§fn copy_to_end_limited(
&mut self,
writer: &mut dyn Write,
max_bytes: u64,
) -> Result<u64, Error>
fn copy_to_end_limited( &mut self, writer: &mut dyn Write, max_bytes: u64, ) -> Result<u64, Error>
Copies the remaining input when it fits within a configured limit.
§Parameters
writer: Destination writer.max_bytes: Maximum accepted remaining byte count.
§Returns
The number of bytes copied.
§Errors
Returns std::io::ErrorKind::OutOfMemory if the temporary copy buffer
cannot be allocated, a read or write error, or
std::io::ErrorKind::InvalidData when the remaining input exceeds
max_bytes or the reader reports more bytes than requested. Bytes
from an invalid read are not written; previously copied bytes are
not rolled back.
Source§fn read_to_end_limited(&mut self, max_len: usize) -> Result<Vec<u8>, Error>
fn read_to_end_limited(&mut self, max_len: usize) -> Result<Vec<u8>, Error>
Reads the remaining bytes into a bounded vector.
§Parameters
max_len: Maximum accepted remaining byte count.
§Returns
A vector containing all remaining bytes.
§Errors
Returns std::io::ErrorKind::OutOfMemory if the result vector cannot
grow, a read error, or std::io::ErrorKind::InvalidData when the
remaining input exceeds max_len or the reader reports more bytes
than requested.
Source§fn read_to_end_limited_into(
&mut self,
output: &mut Vec<u8>,
max_len: usize,
) -> Result<usize, Error>
fn read_to_end_limited_into( &mut self, output: &mut Vec<u8>, max_len: usize, ) -> Result<usize, Error>
Appends the remaining bytes to a bounded vector.
§Parameters
output: Destination vector.max_len: Maximum accepted remaining byte count.
§Returns
The number of bytes appended to output.
§Errors
Returns std::io::ErrorKind::OutOfMemory if output cannot grow, a
read error, or std::io::ErrorKind::InvalidData when the
remaining input exceeds max_len or the reader reports more bytes
than requested.
Source§fn read_to_string_limited(&mut self, max_len: usize) -> Result<String, Error>
fn read_to_string_limited(&mut self, max_len: usize) -> Result<String, Error>
Reads the remaining bytes as bounded UTF-8 text.
§Parameters
max_len: Maximum accepted remaining byte count.
§Returns
The decoded UTF-8 string.
§Errors
Returns std::io::ErrorKind::OutOfMemory if the result buffer cannot
grow, a read error, or std::io::ErrorKind::InvalidData when the
input exceeds max_len or is not valid UTF-8.
Source§fn read_to_string_limited_into(
&mut self,
output: &mut String,
max_len: usize,
) -> Result<usize, Error>
fn read_to_string_limited_into( &mut self, output: &mut String, max_len: usize, ) -> Result<usize, Error>
Appends the remaining bounded UTF-8 text to a string.
§Parameters
output: Destination string.max_len: Maximum accepted remaining byte count.
§Returns
The number of bytes appended to output.
§Errors
Returns std::io::ErrorKind::OutOfMemory if the temporary byte buffer
or output cannot grow, a read error, or
std::io::ErrorKind::InvalidData when the input exceeds max_len
or is not valid UTF-8.
impl<T> ReadSeek for T
Source§impl<T> ReadSeekExt for T
impl<T> ReadSeekExt for T
Source§fn peek_exact_or_eof(&mut self, buffer: &mut [u8]) -> Result<usize, Error>
fn peek_exact_or_eof(&mut self, buffer: &mut [u8]) -> Result<usize, Error>
Reads from the current position and restores it afterward.
§Parameters
buffer: Destination buffer.
§Returns
The number of bytes written into buffer.
§Errors
Returns an error when reading, querying, or restoring the stream
position fails. Returns std::io::ErrorKind::InvalidData if the
reader reports more bytes than requested.
Source§fn read_exact_or_eof_at(
&mut self,
offset: u64,
buffer: &mut [u8],
) -> Result<usize, Error>
fn read_exact_or_eof_at( &mut self, offset: u64, buffer: &mut [u8], ) -> Result<usize, Error>
Reads from an absolute offset and restores the original position.
§Parameters
offset: Absolute byte offset to read from.buffer: Destination buffer.
§Returns
The number of bytes written into buffer.
§Errors
Returns an error when querying, changing, or restoring the stream
position, or when reading fails. Returns
std::io::ErrorKind::InvalidData if the reader reports more bytes
than requested.