Skip to main content

ChiselSource

Trait ChiselSource 

Source
pub trait ChiselSource {
    type Error;

    // Required methods
    fn read_exact(
        &mut self,
        buffer: &mut [u8],
    ) -> Result<(), ChiselSourceError<Self::Error>>;
    fn read_until(
        &mut self,
        byte: u8,
        into: &mut Vec<u8>,
    ) -> Result<ReadUntilStopReason, Self::Error>;
    fn skip(
        &mut self,
        how_many: usize,
    ) -> Result<(), ChiselSourceError<Self::Error>>;
}
Expand description

A “source” for chiseling bytes out of.

This is analogous to the standard library Read and/or BufRead traits, but specialized for chiseling operations.

Required Associated Types§

Source

type Error

The type of errors returned by this source.

Required Methods§

Source

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

Reads the exact number of bytes to fill buffer.

§Errors

If an end-of-input condition occurs before completely filling the buffer, ChiselSourceError::EndOfInput is returned.

If any other error occurs while reading, this function immediately returns with ChiselSourceError::Underlying(_).

If any error is returned, the contents of buffer are unspecified. How many bytes were read is also unspecified, except that at most buffer.len() bytes are read.

Source

fn read_until( &mut self, byte: u8, into: &mut Vec<u8>, ) -> Result<ReadUntilStopReason, Self::Error>

Reads until the given delimiter byte is found or end-of-input occurs.

If end-of-input occurs before the delimiter byte is found, ReadUntilStopReason::EndOfInput is returned.

Otherwise, ReadUntilStopReason::Delimiter is returned. The found delimiter is not added to into.

§Errors

If an error occurs while reading, this function immediately returns with ChiselSourceError::Underlying(_). If this occurs, the contents of into are unspecified. How many bytes were read is also unspecified, with no restrictions.

Note that end-of-input conditions are not errors, and result in Ok(ReadUntilStopReason::EndOfInput).

Source

fn skip( &mut self, how_many: usize, ) -> Result<(), ChiselSourceError<Self::Error>>

Skips some number of bytes of the input.

This is usually used for padding or alignment.

§Errors

If end-of-input condition occurs before how_many bytes are skipped, ChiselSourceError::EndOfInput is returned.

If any other error occurs while skipping, this function immediately returns with ``ChiselSourceError::Underlying(_)`.

If any error is returned, it is unspecified how many bytes are skipped, except that at most how_many bytes are be skipped.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementations on Foreign Types§

Source§

impl ChiselSource for &[u8]

Source§

type Error = !

Source§

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

Source§

fn read_until( &mut self, byte: u8, into: &mut Vec<u8>, ) -> Result<ReadUntilStopReason, Self::Error>

Source§

fn skip( &mut self, how_many: usize, ) -> Result<(), ChiselSourceError<Self::Error>>

Implementors§

Source§

impl<R: BufRead> ChiselSource for ChiselSourceBufRead<R>

Available on crate feature std only.
Source§

impl<R: Read> ChiselSource for ChiselSourceRead<R>

Available on crate feature std only.