Skip to main content

Read

Trait Read 

Source
pub trait Read {
    // Required method
    fn read_some(&mut self, buf: &mut [u8]) -> usize;
}
Expand description

The minimal byte source Digest::from_stream reads from.

The kit is no_std and core-only, so it cannot name std::io::Read; this trait carries the one operation a digest needs: pull some bytes now, returning how many. Host code adapts a real reader in one line, e.g. for std::io::Read: fn read_some(&mut self, buf: &mut [u8]) -> usize { self.0.read(buf).unwrap_or(0) } — an I/O error surfaces as exhaustion, which from_stream reports as Error::Truncated.

Required Methods§

Source

fn read_some(&mut self, buf: &mut [u8]) -> usize

Pulls as many bytes as the source can supply right now into buf and returns how many were written. Never writes more than buf.len(). Returning 0 signals that the source is exhausted.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl Read for &[u8]

Source§

fn read_some(&mut self, buf: &mut [u8]) -> usize

Implementors§