Skip to main content

Streams

Enum Streams 

Source
pub enum Streams {}
Expand description

Stream utility namespace.

This type is an uninstantiable namespace for operations involving one or more Read or Write values. The methods do not close or flush the supplied streams unless the underlying standard-library operation documents otherwise.

§Examples

use qubit_io::Streams;
use std::io::Cursor;

let mut input = Cursor::new(b"abcdef".to_vec());
let mut output = Vec::new();

let copied = Streams::copy_at_most(&mut input, &mut output, 4)?;

assert_eq!(4, copied);
assert_eq!(b"abcd", output.as_slice());

Implementations§

Source§

impl Streams

Source

pub fn copy<R, W>(reader: &mut R, writer: &mut W) -> Result<u64>
where R: Read + ?Sized, W: Write + ?Sized,

Copies all remaining bytes from reader to writer.

This is a namespace-style wrapper around std::io::copy. It preserves the standard-library behavior, including platform-specific optimized copy paths when available.

§Parameters
  • reader: Source reader.
  • writer: Destination writer.
§Returns

The number of bytes copied.

§Errors

Returns the first read or write error reported by the underlying streams, using the same error behavior as std::io::copy.

Source

pub fn copy_at_most<R, W>( reader: &mut R, writer: &mut W, max_bytes: u64, ) -> Result<u64>
where R: Read + ?Sized, W: Write + ?Sized,

Copies at most max_bytes bytes from reader to writer.

This method stops successfully when either EOF is reached or max_bytes bytes have been copied. It does not close or flush either stream.

§Parameters
  • reader: Source reader.
  • writer: Destination writer.
  • max_bytes: Maximum number of bytes to copy.
§Returns

The number of bytes copied.

§Errors

Returns the first non-interrupted read error or write error reported by the underlying streams. Interrupted reads are retried.

Source

pub fn copy_at_most_with_buffer_size<R, W>( reader: &mut R, writer: &mut W, max_bytes: u64, buffer_size: usize, ) -> Result<u64>
where R: Read + ?Sized, W: Write + ?Sized,

Copies at most max_bytes bytes from reader to writer using a caller-selected heap buffer.

This method has the same copy semantics as Self::copy_at_most, but allocates a buffer on the heap with buffer_size bytes. Use it when the default chunk size is too large for the caller’s stack budget or when a smaller copy window is desirable.

§Parameters
  • reader: Source reader.
  • writer: Destination writer.
  • max_bytes: Maximum number of bytes to copy.
  • buffer_size: Number of bytes in the copy buffer.
§Returns

The number of bytes copied.

§Errors

Returns ErrorKind::InvalidInput when buffer_size == 0. Returns an allocation error if the copy buffer cannot be allocated. Returns the first non-interrupted read error or write error reported by the underlying streams. Interrupted reads are retried.

Source

pub fn copy_to_end_limited<R, W>( reader: &mut R, writer: &mut W, max_bytes: u64, ) -> Result<u64>
where R: Read + ?Sized, W: Write + ?Sized,

Copies the remaining input if its total length is at most max_bytes.

This method copies from the current reader position until EOF. If EOF is not reached within max_bytes bytes, it returns std::io::ErrorKind::InvalidData. Detecting oversized input consumes one excess byte from reader; that excess byte is not written to writer.

Unlike bounded reads into in-memory collections, this method cannot roll back bytes already accepted by writer when the limit is exceeded because Write does not provide truncation. On std::io::ErrorKind::InvalidData, up to max_bytes bytes may remain in writer.

§Parameters
  • reader: Source reader.
  • writer: Destination writer.
  • max_bytes: Maximum accepted number of bytes in the remaining input.
§Returns

The number of bytes copied when EOF is reached within the limit.

§Errors

Returns std::io::ErrorKind::InvalidData when the remaining input is longer than max_bytes. Returns the first non-interrupted read error or write error reported by the underlying streams. Interrupted reads are retried.

Source

pub fn copy_input_to_output<I, O>(input: &mut I, output: &mut O) -> Result<u64>
where I: Input + ?Sized, O: Output<Item = I::Item> + ?Sized, I::Item: Copy + Default,

Copies all remaining items from input to output.

This method allocates a reusable item buffer and copies until EOF. It does not close or flush output.

§Parameters
  • input: Source item input.
  • output: Destination item output.
§Returns

The number of items copied.

§Errors

Returns the first non-interrupted read error or output error reported by the underlying streams. Returns ErrorKind::InvalidData if an input or output reports an impossible item count.

Source

pub fn copy_input_to_output_at_most<I, O>( input: &mut I, output: &mut O, max_items: u64, ) -> Result<u64>
where I: Input + ?Sized, O: Output<Item = I::Item> + ?Sized, I::Item: Copy + Default,

Copies at most max_items items from input to output.

This method stops successfully when either EOF is reached or max_items items have been copied. It does not close or flush output.

§Parameters
  • input: Source item input.
  • output: Destination item output.
  • max_items: Maximum number of items to copy.
§Returns

The number of items copied.

§Errors

Returns the first non-interrupted read error or output error reported by the underlying streams. Returns ErrorKind::InvalidData if an input or output reports an impossible item count.

Source

pub fn copy_input_to_output_end_limited<I, O>( input: &mut I, output: &mut O, max_items: u64, ) -> Result<u64>
where I: Input + ?Sized, O: Output<Item = I::Item> + ?Sized, I::Item: Copy + Default,

Copies the remaining input if its total length is at most max_items.

This method copies from the current input position until EOF. If EOF is not reached within max_items items, it returns ErrorKind::InvalidData. Detecting oversized input consumes one excess item from input; that excess item is not written to output.

Oversized input, read errors, and allocation failures before output flushing leave output unchanged. Once EOF is reached and collected items are written to output, a write error may leave partial items accepted by output because Output has no rollback operation.

§Parameters
  • input: Source item input.
  • output: Destination item output.
  • max_items: Maximum accepted number of remaining input items.
§Returns

The number of items copied when EOF is reached within the limit.

§Errors

Returns ErrorKind::InvalidData when the remaining input is longer than max_items, or when an input reports an impossible item count. Returns the first non-interrupted read error or output error reported by the underlying streams.

Source

pub fn content_eq(left: &mut dyn Read, right: &mut dyn Read) -> Result<bool>

Tests whether two readable streams have equal remaining contents.

The comparison starts at each reader’s current position and reads both streams in fixed-size chunks. A mismatch stops comparison immediately after the differing chunks are read, so each reader may have advanced past the first differing byte within that chunk.

§Parameters
  • left: First stream.
  • right: Second stream.
§Returns

true when both streams produce the same bytes until EOF.

§Errors

Returns the first read error reported by either stream.

Source

pub fn compare_content( left: &mut dyn Read, right: &mut dyn Read, ) -> Result<Ordering>

Lexicographically compares the remaining contents of two readable streams.

The comparison starts at each reader’s current position and reads both streams in fixed-size chunks. A mismatch stops comparison immediately after the differing chunks are read, so each reader may have advanced past the first differing byte within that chunk.

§Parameters
  • left: First stream.
  • right: Second stream.
§Returns

The lexicographic ordering of the remaining bytes.

§Errors

Returns the first read error reported by either stream.

Source

pub fn compare_content_with_buffer_size( left: &mut dyn Read, right: &mut dyn Read, buffer_size: usize, ) -> Result<Ordering>

Lexicographically compares the remaining contents of two readable streams using caller-selected heap buffers.

This method has the same comparison and stream-advance semantics as Self::compare_content, but allocates two buffers on the heap with buffer_size bytes each. Use it when the default chunk size is too large for the caller’s stack budget or when a smaller comparison window is desirable.

§Parameters
  • left: First stream.
  • right: Second stream.
  • buffer_size: Number of bytes in each comparison buffer.
§Returns

The lexicographic ordering of the remaining bytes.

§Errors

Returns ErrorKind::InvalidInput when buffer_size == 0. Returns an allocation error if the comparison buffers cannot be allocated. Returns the first read error reported by either stream.

Auto Trait Implementations§

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> 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, 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.