Skip to main content

StreamReader

Struct StreamReader 

Source
pub struct StreamReader<R> { /* private fields */ }
Expand description

Reads tensors from an async source in the Hurray streaming wire format.

Call next_tensor in a loop until it returns Ok(None) (clean EOF).

§Examples

use hurray_io::stream::StreamReader;

let wire: &[u8] = &[]; // replace with actual data
let mut reader = StreamReader::new(wire);
while let Some(tensor) = reader.next_tensor().await? {
    println!(
        "tensor with {} buffer(s)",
        tensor.buffers.len()
    );
}

Implementations§

Source§

impl<R: AsyncRead + Unpin> StreamReader<R>

Source

pub fn new(inner: R) -> Self

Creates a reader with default options.

Source

pub fn cross_machine(inner: R) -> Self

Creates a reader that enforces ProducerSynced on every buffer.

Use when the stream was produced by a remote machine and GPU/semaphore sync primitives are not meaningful locally.

Source

pub fn with_options(inner: R, options: StreamReaderOptions) -> Self

Creates a reader with custom options.

Source

pub async fn next_tensor(&mut self) -> Result<Option<StreamTensor>>

Reads the next tensor from the stream.

Returns Ok(None) on a clean EOF (no bytes remaining before a descriptor starts).

§Errors
Source

pub async fn next_item(&mut self) -> Result<Option<StreamItem>>

Reads the next item, assembling composites (head + members) into a StreamItem::Composite and validating them.

When the next descriptor on the wire is a composite head (layout_tag = 0x0B), this reads its declared member_count members — each of which may itself be a composite (recursion) — validates the group with [CompositeValidator] (member count, plus partition coverage / overlay ordering), and returns them together. Otherwise it behaves like next_tensor, returning a StreamItem::Tensor. Returns Ok(None) on a clean EOF.

§Examples
use hurray_io::stream::{StreamItem, StreamReader};

let wire: &[u8] = &[]; // replace with actual data
let mut reader = StreamReader::new(wire);
while let Some(item) = reader.next_item().await? {
    match item {
        StreamItem::Tensor(t) => println!("tensor, {} buffer(s)", t.buffers.len()),
        StreamItem::Composite(c) => println!("composite, {} member(s)", c.members.len()),
    }
}
§Errors

In addition to the errors of next_tensor:

Source

pub fn into_inner(self) -> R

Returns the underlying reader.

Auto Trait Implementations§

§

impl<R> Freeze for StreamReader<R>
where R: Freeze,

§

impl<R> RefUnwindSafe for StreamReader<R>
where R: RefUnwindSafe,

§

impl<R> Send for StreamReader<R>
where R: Send,

§

impl<R> Sync for StreamReader<R>
where R: Sync,

§

impl<R> Unpin for StreamReader<R>
where R: Unpin,

§

impl<R> UnsafeUnpin for StreamReader<R>
where R: UnsafeUnpin,

§

impl<R> UnwindSafe for StreamReader<R>
where R: 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> 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.