Skip to main content

Stream

Struct Stream 

Source
pub struct Stream<'env, D> { /* private fields */ }
Expand description

The messages of one stream call, and the places for their digests, borrowed for its scope; D is the stream’s handler.

Implementations§

Source§

impl<'env, D: FnMut(&'env mut [Hash])> Stream<'env, D>

Source

pub fn submit(&mut self, message: &'env [u8], out: &'env mut Hash)

Hash message where it is, its digest into out.

Source

pub fn submit_with( &mut self, len: usize, fill: impl FnMut(usize, &mut [u8]), out: &'env mut Hash, )

Hash a message of len bytes that fill writes in place, into the stream’s own bytes, in pieces of up to 64 KiB, its digest into out: fill(at, room) writes the message’s bytes from at into all of room (a read from a file or socket straight into the stream). Each room starts on a 64-byte boundary. The stream reuses the bytes once out is handed back; a stream keeps 2 MiB of them, and submit_with waits for room as submit does.

Source

pub fn submit_reader( &mut self, reader: impl Read, size_hint: Option<u64>, out: &'env mut Hash, ) -> Result<u64>

Hash the message reader yields, to its end, read straight into the stream’s own bytes in pieces of up to 64 KiB (a file or socket read into the stream, overlapping the hashing of earlier pieces), its digest into out: the message’s length on success. On a read error (other than an interruption, which reads again) the error returns, out gets no digest and is not handed back, and the stream goes on with the next message. The length need not be known: the stream reads one piece ahead to tell the last.

size_hint is the length the caller expects, where it knows one (a file’s size, a protocol’s length field): a scheduling hint, never part of the hash, so a wrong one costs nothing but speed. Today the stream does not use it; it is here so that a stream that schedules by it later changes no caller.

Source

pub fn submit_batch( &mut self, batch: &'env [u8], message_len: usize, out: &'env mut [Hash], )

Hash a batch of messages of message_len bytes where it is, laid out as hash_many takes them (each in whole blocks, zero after its bytes), a digest per message into out, in the messages’ order: out holds one per message. The batch goes in parts of up to 64 KiB, each one entry; out comes back whole.

Source

pub fn submit_batch_with( &mut self, message_len: usize, fill: impl FnMut(usize, &mut [u8]), out: &'env mut [Hash], )

Hash a batch of out.len() messages of message_len bytes that fill writes in place, laid out as hash_many takes them: fill(at, room) writes the batch’s bytes from at (padding included: each message in whole blocks, zero after its bytes) into all of room, a part of up to 64 KiB at a time. As submit_with and submit_batch.

Source

pub fn collect(&mut self)

Hand back every place whose digests are done, in order, without waiting; and hand the open task to the pool, so what it holds starts hashing.

Source

pub fn finish(&mut self)

Hand back every place, in order, once its digests are done: this thread hashes any task no thread has taken, and waits for the rest.

Trait Implementations§

Source§

impl<D> Drop for Stream<'_, D>

Source§

fn drop(&mut self)

Wait for every task still reading the messages and writing the places (also when the body panicked), then keep the storage as the thread’s spare. A stream lives only inside stream, which owns it, so this runs before the scope ends.

Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl<D: Send> Send for Stream<'_, D>

Auto Trait Implementations§

§

impl<'env, D> !RefUnwindSafe for Stream<'env, D>

§

impl<'env, D> !Sync for Stream<'env, D>

§

impl<'env, D> !UnwindSafe for Stream<'env, D>

§

impl<'env, D> Freeze for Stream<'env, D>
where D: Freeze,

§

impl<'env, D> Unpin for Stream<'env, D>
where D: Unpin,

§

impl<'env, D> UnsafeUnpin for Stream<'env, D>
where D: UnsafeUnpin,

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.