Skip to main content

TeeReader

Struct TeeReader 

Source
pub struct TeeReader<R, W> { /* private fields */ }
Expand description

Reader wrapper that mirrors read bytes into a branch writer.

TeeReader forwards reads to the source reader and writes every successfully read byte into the branch writer while the stream is consumed. If the branch writer fails, the source bytes have already been read from the inner reader and the branch error is returned.

§Examples

use std::io::{
    Cursor,
    Read,
};

use qubit_io::TeeReader;

let source = Cursor::new(b"abc".to_vec());
let branch = Vec::new();
let mut reader = TeeReader::new(source, branch);

let mut data = Vec::new();
reader.read_to_end(&mut data)?;
let (_source, branch) = reader.into_inner();

assert_eq!(b"abc", data.as_slice());
assert_eq!(b"abc", branch.as_slice());

Implementations§

Source§

impl<R, W> TeeReader<R, W>

Source

pub fn new(reader: R, branch: W) -> Self

Creates a tee reader.

§Parameters
  • reader: Source reader.
  • branch: Writer that receives the bytes successfully read.
§Returns

A new tee reader.

Source

pub fn reader_ref(&self) -> &R

Returns an immutable reference to the source reader.

§Returns

The source reader reference.

Source

pub fn reader_mut(&mut self) -> &mut R

Returns a mutable reference to the source reader.

§Returns

The source reader reference.

Source

pub fn branch_ref(&self) -> &W

Returns an immutable reference to the branch writer.

§Returns

The branch writer reference.

Source

pub fn branch_mut(&mut self) -> &mut W

Returns a mutable reference to the branch writer.

§Returns

The branch writer reference.

Source

pub fn into_inner(self) -> (R, W)

Consumes this wrapper and returns the source reader and branch writer.

§Returns

A tuple containing the source reader and branch writer.

Trait Implementations§

Source§

impl<R, W> Read for TeeReader<R, W>
where R: Read, W: Write,

Source§

fn read(&mut self, buffer: &mut [u8]) -> Result<usize>

Pull some bytes from this source into the specified buffer, returning how many bytes were read. Read more
1.36.0 · Source§

fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>

Like read, except that it reads into a slice of buffers. Read more
Source§

fn is_read_vectored(&self) -> bool

🔬This is a nightly-only experimental API. (can_vector)
Determines if this Reader has an efficient read_vectored implementation. Read more
1.0.0 · Source§

fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>

Reads all bytes until EOF in this source, placing them into buf. Read more
1.0.0 · Source§

fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>

Reads all bytes until EOF in this source, appending them to buf. Read more
1.6.0 · Source§

fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>

Reads the exact number of bytes required to fill buf. Read more
Source§

fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>

🔬This is a nightly-only experimental API. (read_buf)
Pull some bytes from this source into the specified buffer. Read more
Source§

fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>

🔬This is a nightly-only experimental API. (read_buf)
Reads the exact number of bytes required to fill cursor. Read more
1.0.0 · Source§

fn by_ref(&mut self) -> &mut Self
where Self: Sized,

Creates a “by reference” adapter for this instance of Read. Read more
1.0.0 · Source§

fn bytes(self) -> Bytes<Self>
where Self: Sized,

Transforms this Read instance to an Iterator over its bytes. Read more
1.0.0 · Source§

fn chain<R>(self, next: R) -> Chain<Self, R>
where R: Read, Self: Sized,

Creates an adapter which will chain this stream with another. Read more
1.0.0 · Source§

fn take(self, limit: u64) -> Take<Self>
where Self: Sized,

Creates an adapter which will read at most limit bytes from it. Read more
Source§

fn read_array<const N: usize>(&mut self) -> Result<[u8; N], Error>
where Self: Sized,

🔬This is a nightly-only experimental API. (read_array)
Read and return a fixed array of bytes from this source. Read more
Source§

impl<R, W> Seek for TeeReader<R, W>
where R: Seek,

Source§

fn seek(&mut self, position: SeekFrom) -> Result<u64>

Seek to an offset, in bytes, in a stream. Read more
1.55.0 · Source§

fn rewind(&mut self) -> Result<(), Error>

Rewind to the beginning of a stream. Read more
Source§

fn stream_len(&mut self) -> Result<u64, Error>

🔬This is a nightly-only experimental API. (seek_stream_len)
Returns the length of this stream (in bytes). Read more
1.51.0 · Source§

fn stream_position(&mut self) -> Result<u64, Error>

Returns the current seek position from the start of the stream. Read more
1.80.0 · Source§

fn seek_relative(&mut self, offset: i64) -> Result<(), Error>

Seeks relative to the current position. Read more

Auto Trait Implementations§

§

impl<R, W> Freeze for TeeReader<R, W>
where R: Freeze, W: Freeze,

§

impl<R, W> RefUnwindSafe for TeeReader<R, W>

§

impl<R, W> Send for TeeReader<R, W>
where R: Send, W: Send,

§

impl<R, W> Sync for TeeReader<R, W>
where R: Sync, W: Sync,

§

impl<R, W> Unpin for TeeReader<R, W>
where R: Unpin, W: Unpin,

§

impl<R, W> UnsafeUnpin for TeeReader<R, W>
where R: UnsafeUnpin, W: UnsafeUnpin,

§

impl<R, W> UnwindSafe for TeeReader<R, W>
where R: UnwindSafe, W: UnwindSafe,

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> BinaryReadExt for T
where T: Read + ?Sized,

Source§

fn read_u8(&mut self) -> Result<u8, Error>

Reads one unsigned byte. Read more
Source§

fn read_i8(&mut self) -> Result<i8, Error>

Reads one signed byte. Read more
Source§

fn read_u16_be(&mut self) -> Result<u16, Error>

Reads a big-endian u16. Read more
Source§

fn read_u16_le(&mut self) -> Result<u16, Error>

Reads a little-endian u16. Read more
Source§

fn read_i16_be(&mut self) -> Result<i16, Error>

Reads a big-endian i16. Read more
Source§

fn read_i16_le(&mut self) -> Result<i16, Error>

Reads a little-endian i16. Read more
Source§

fn read_u32_be(&mut self) -> Result<u32, Error>

Reads a big-endian u32. Read more
Source§

fn read_u32_le(&mut self) -> Result<u32, Error>

Reads a little-endian u32. Read more
Source§

fn read_i32_be(&mut self) -> Result<i32, Error>

Reads a big-endian i32. Read more
Source§

fn read_i32_le(&mut self) -> Result<i32, Error>

Reads a little-endian i32. Read more
Source§

fn read_u64_be(&mut self) -> Result<u64, Error>

Reads a big-endian u64. Read more
Source§

fn read_u64_le(&mut self) -> Result<u64, Error>

Reads a little-endian u64. Read more
Source§

fn read_i64_be(&mut self) -> Result<i64, Error>

Reads a big-endian i64. Read more
Source§

fn read_i64_le(&mut self) -> Result<i64, Error>

Reads a little-endian i64. Read more
Source§

fn read_u128_be(&mut self) -> Result<u128, Error>

Reads a big-endian u128. Read more
Source§

fn read_u128_le(&mut self) -> Result<u128, Error>

Reads a little-endian u128. Read more
Source§

fn read_i128_be(&mut self) -> Result<i128, Error>

Reads a big-endian i128. Read more
Source§

fn read_i128_le(&mut self) -> Result<i128, Error>

Reads a little-endian i128. Read more
Source§

fn read_f32_be(&mut self) -> Result<f32, Error>

Reads a big-endian IEEE-754 f32. Read more
Source§

fn read_f32_le(&mut self) -> Result<f32, Error>

Reads a little-endian IEEE-754 f32. Read more
Source§

fn read_f64_be(&mut self) -> Result<f64, Error>

Reads a big-endian IEEE-754 f64. Read more
Source§

fn read_f64_le(&mut self) -> Result<f64, Error>

Reads a little-endian IEEE-754 f64. Read more
Source§

fn read_u16(&mut self, order: ByteOrder) -> Result<u16>

Reads a u16 using order. Read more
Source§

fn read_i16(&mut self, order: ByteOrder) -> Result<i16>

Reads an i16 using order. Read more
Source§

fn read_u32(&mut self, order: ByteOrder) -> Result<u32>

Reads a u32 using order. Read more
Source§

fn read_i32(&mut self, order: ByteOrder) -> Result<i32>

Reads an i32 using order. Read more
Source§

fn read_u64(&mut self, order: ByteOrder) -> Result<u64>

Reads a u64 using order. Read more
Source§

fn read_i64(&mut self, order: ByteOrder) -> Result<i64>

Reads an i64 using order. Read more
Source§

fn read_u128(&mut self, order: ByteOrder) -> Result<u128>

Reads a u128 using order. Read more
Source§

fn read_i128(&mut self, order: ByteOrder) -> Result<i128>

Reads an i128 using order. Read more
Source§

fn read_f32(&mut self, order: ByteOrder) -> Result<f32>

Reads an IEEE-754 f32 using order. Read more
Source§

fn read_f64(&mut self, order: ByteOrder) -> Result<f64>

Reads an IEEE-754 f64 using order. 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> Leb128ReadExt for T
where T: Read + ?Sized,

Source§

fn read_uleb_u8(&mut self) -> Result<u8, Error>

Reads an unsigned LEB128 u8. Read more
Source§

fn read_uleb_u8_strict(&mut self) -> Result<u8, Error>

Reads a canonical unsigned LEB128 u8. Read more
Source§

fn read_uleb_u16(&mut self) -> Result<u16, Error>

Reads an unsigned LEB128 u16. Read more
Source§

fn read_uleb_u16_strict(&mut self) -> Result<u16, Error>

Reads a canonical unsigned LEB128 u16. Read more
Source§

fn read_uleb_u32(&mut self) -> Result<u32, Error>

Reads an unsigned LEB128 u32. Read more
Source§

fn read_uleb_u32_strict(&mut self) -> Result<u32, Error>

Reads a canonical unsigned LEB128 u32. Read more
Source§

fn read_uleb_u64(&mut self) -> Result<u64, Error>

Reads an unsigned LEB128 u64. Read more
Source§

fn read_uleb_u64_strict(&mut self) -> Result<u64, Error>

Reads a canonical unsigned LEB128 u64. Read more
Source§

fn read_uleb_u128(&mut self) -> Result<u128, Error>

Reads an unsigned LEB128 u128. Read more
Source§

fn read_uleb_u128_strict(&mut self) -> Result<u128, Error>

Reads a canonical unsigned LEB128 u128. Read more
Source§

fn read_uleb_usize(&mut self) -> Result<usize, Error>

Reads an unsigned LEB128 usize. Read more
Source§

fn read_uleb_usize_strict(&mut self) -> Result<usize, Error>

Reads a canonical unsigned LEB128 usize. Read more
Source§

fn read_sleb_i8(&mut self) -> Result<i8, Error>

Reads a signed LEB128 i8. Read more
Source§

fn read_sleb_i8_strict(&mut self) -> Result<i8, Error>

Reads a canonical signed LEB128 i8. Read more
Source§

fn read_sleb_i16(&mut self) -> Result<i16, Error>

Reads a signed LEB128 i16. Read more
Source§

fn read_sleb_i16_strict(&mut self) -> Result<i16, Error>

Reads a canonical signed LEB128 i16. Read more
Source§

fn read_sleb_i32(&mut self) -> Result<i32, Error>

Reads a signed LEB128 i32. Read more
Source§

fn read_sleb_i32_strict(&mut self) -> Result<i32, Error>

Reads a canonical signed LEB128 i32. Read more
Source§

fn read_sleb_i64(&mut self) -> Result<i64, Error>

Reads a signed LEB128 i64. Read more
Source§

fn read_sleb_i64_strict(&mut self) -> Result<i64, Error>

Reads a canonical signed LEB128 i64. Read more
Source§

fn read_sleb_i128(&mut self) -> Result<i128, Error>

Reads a signed LEB128 i128. Read more
Source§

fn read_sleb_i128_strict(&mut self) -> Result<i128, Error>

Reads a canonical signed LEB128 i128. Read more
Source§

fn read_sleb_isize(&mut self) -> Result<isize, Error>

Reads a signed LEB128 isize. Read more
Source§

fn read_sleb_isize_strict(&mut self) -> Result<isize, Error>

Reads a canonical signed LEB128 isize. Read more
Source§

impl<T> ReadExt for T
where T: Read + ?Sized,

Source§

fn read_exact_or_eof(&mut self, buffer: &mut [u8]) -> Result<usize, Error>

Reads bytes until buffer is full or EOF is reached. Read more
Source§

fn read_exact_array<const N: usize>(&mut self) -> Result<[u8; N], Error>

Reads exactly N bytes into a stack-allocated array. Read more
Source§

fn read_exact_vec_limited( &mut self, len: usize, max_len: usize, ) -> Result<Vec<u8>, Error>

Reads exactly len bytes into a new vector after checking a limit. Read more
Source§

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 output. Read more
Source§

fn discard_exact_or_eof(&mut self, bytes: u64) -> Result<u64, Error>

Discards up to bytes bytes from this reader. Read more
Source§

fn copy_to(&mut self, writer: &mut dyn Write) -> Result<u64, Error>

Copies all remaining bytes from this reader into writer. Read more
Source§

fn copy_to_at_most( &mut self, writer: &mut dyn Write, max_bytes: u64, ) -> Result<u64, Error>

Copies at most max_bytes bytes from this reader into writer. Read more
Source§

fn copy_to_end_limited( &mut self, writer: &mut dyn Write, max_bytes: u64, ) -> Result<u64, Error>

Copies the remaining input if its total length is at most max_bytes. Read more
Source§

fn read_to_end_limited(&mut self, max_len: usize) -> Result<Vec<u8>, Error>

Reads the remaining bytes into a vector with a maximum accepted length. Read more
Source§

fn read_to_end_limited_into( &mut self, output: &mut Vec<u8>, max_len: usize, ) -> Result<usize, Error>

Reads the remaining bytes into output with a maximum accepted length. Read more
Source§

fn read_to_string_limited(&mut self, max_len: usize) -> Result<String, Error>

Reads the remaining bytes as UTF-8 text with a maximum accepted length. Read more
Source§

fn read_to_string_limited_into( &mut self, output: &mut String, max_len: usize, ) -> Result<usize, Error>

Reads the remaining bytes as UTF-8 text and appends to output. Read more
Source§

impl<T> ReadSeekExt for T
where T: Read + Seek + ?Sized,

Source§

fn peek_exact_or_eof(&mut self, buffer: &mut [u8]) -> Result<usize, Error>

Reads from the current position and restores the original position. Read more
Source§

fn read_exact_or_eof_at( &mut self, offset: u64, buffer: &mut [u8], ) -> Result<usize, Error>

Reads from offset and restores the original position. Read more
Source§

impl<T> SeekExt for T
where T: Seek + ?Sized,

Source§

fn stream_size(&mut self) -> Result<u64, Error>

Gets the stream size without changing the final stream position. Read more
Source§

impl<T> StringReadExt for T
where T: Read + ?Sized,

Source§

fn read_utf8_string_uleb(&mut self, max_len: usize) -> Result<String, Error>

Reads a UTF-8 string with an unsigned LEB128 byte-length prefix. Read more
Source§

fn read_utf8_string_uleb_strict( &mut self, max_len: usize, ) -> Result<String, Error>

Reads a UTF-8 string with a canonical unsigned LEB128 byte-length prefix. Read more
Source§

fn read_utf8_string_u16_be(&mut self, max_len: usize) -> Result<String, Error>

Reads a UTF-8 string with a big-endian u16 byte-length prefix. Read more
Source§

fn read_utf8_string_u16_le(&mut self, max_len: usize) -> Result<String, Error>

Reads a UTF-8 string with a little-endian u16 byte-length prefix. Read more
Source§

fn read_utf8_string_u32_be(&mut self, max_len: usize) -> Result<String, Error>

Reads a UTF-8 string with a big-endian u32 byte-length prefix. Read more
Source§

fn read_utf8_string_u32_le(&mut self, max_len: usize) -> Result<String, Error>

Reads a UTF-8 string with a little-endian u32 byte-length prefix. Read more
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.
Source§

impl<T> ZigZagReadExt for T
where T: Read + ?Sized,

Source§

fn read_zigzag_i8(&mut self) -> Result<i8, Error>

Reads a ZigZag encoded i8. Read more
Source§

fn read_zigzag_i8_strict(&mut self) -> Result<i8, Error>

Reads a canonical ZigZag encoded i8. Read more
Source§

fn read_zigzag_i16(&mut self) -> Result<i16, Error>

Reads a ZigZag encoded i16. Read more
Source§

fn read_zigzag_i16_strict(&mut self) -> Result<i16, Error>

Reads a canonical ZigZag encoded i16. Read more
Source§

fn read_zigzag_i32(&mut self) -> Result<i32, Error>

Reads a ZigZag encoded i32. Read more
Source§

fn read_zigzag_i32_strict(&mut self) -> Result<i32, Error>

Reads a canonical ZigZag encoded i32. Read more
Source§

fn read_zigzag_i64(&mut self) -> Result<i64, Error>

Reads a ZigZag encoded i64. Read more
Source§

fn read_zigzag_i64_strict(&mut self) -> Result<i64, Error>

Reads a canonical ZigZag encoded i64. Read more
Source§

fn read_zigzag_i128(&mut self) -> Result<i128, Error>

Reads a ZigZag encoded i128. Read more
Source§

fn read_zigzag_i128_strict(&mut self) -> Result<i128, Error>

Reads a canonical ZigZag encoded i128. Read more
Source§

fn read_zigzag_isize(&mut self) -> Result<isize, Error>

Reads a ZigZag encoded isize. Read more
Source§

fn read_zigzag_isize_strict(&mut self) -> Result<isize, Error>

Reads a canonical ZigZag encoded isize. Read more
Source§

impl<T> ReadSeek for T
where T: Read + Seek + ?Sized,