Chisel

Struct Chisel 

Source
pub struct Chisel<S> { /* private fields */ }
Expand description

An object providing structured access to an underlying byte-stream.

A Chisel is an abstraction over some “source” of bytes that allows reading data in a structured manner.

See the crate documentation for more information.

Implementations§

Source§

impl<'a> Chisel<&'a [u8]>

Source

pub fn from_array(buf: &'a [u8]) -> Self

Create a new Chisel, with its source being an array of bytes.

Source§

impl<'a, T: Read> Chisel<ChiselSourceRead<'a, T>>

Source

pub fn from_read(read: &'a mut T) -> Self

Create a new Chisel, with its source being a Read implementation.

Note that typical chiseling operations involve a lot of individual calls to read. As such, it is recommended to instead use from_buf_read whenever possible.

Only use this constructor in the rare circumstance in which it is absolutely necessary to perform direct, unbuffered reads from an I/O source.

Source§

impl<'a, T: BufRead> Chisel<ChiselSourceBufRead<'a, T>>

Source

pub fn from_buf_read(read: &'a mut T) -> Self

Create a new Chisel, with its source being a BufRead implementation.

Source§

impl<S: ChiselSource> Chisel<S>

Source

pub fn new(source: S) -> Self

Creates a new Chisel from an arbitrary source.

Source

pub fn offset(&self) -> usize

Returns the current byte offset of the Chisel.

Source

pub fn error<E>(&self, err: E, backstep: usize) -> ChiselError<E, S::Error>

Returns a format error that occurred backstep bytes ago.

This is a convenience method for manually determining the appropriate byte offset and calling ChiselError::format.

Source

pub fn little_endian(&mut self) -> ChiselLittleEndian<'_, S>

Returns an Endianness::Little-wrapper around this chisel. The wrapper reads values in the little-endian byte order.

Source

pub fn big_endian(&mut self) -> ChiselBigEndian<'_, S>

Returns an Endianness::Big-wrapper around this chisel. The wrapper reads values in the big-endian byte order.

Source

pub fn read_buf(&mut self, buf: &mut [u8]) -> InfallibleFormatResult<(), S>

Fills a provided buffer with bytes from the source.

§Errors

This function returns an ChiselErrorData::EndOfInput if the end of the input is encountered before the buffer is completely filled.

If an error is returned, the contents of buf are unspecified and the chisel breaks.

Source

pub fn u8(&mut self) -> InfallibleFormatResult<u8, S>

Reads a single byte u8.

As this function only reads a single byte, no endianness is required.

Source

pub fn u16(&mut self, endian: Endianness) -> InfallibleFormatResult<u16, S>

Reads a single u16.

The provided endian specifies the byte order.

§Errors

If an error is returned, the chisel breaks.

Source

pub fn u32(&mut self, endian: Endianness) -> InfallibleFormatResult<u32, S>

Reads a single u32.

The provided endian specifies the byte order.

§Errors

If an error is returned, the chisel breaks.

Source

pub fn u64(&mut self, endian: Endianness) -> InfallibleFormatResult<u64, S>

Reads a single u64.

The provided endian specifies the byte order.

§Errors

If an error is returned, the chisel breaks.

Source

pub fn i8(&mut self) -> InfallibleFormatResult<i8, S>

Reads a single signed byte i8.

As this function only reads a single byte, no endianness is required.

Source

pub fn i16(&mut self, endian: Endianness) -> InfallibleFormatResult<i16, S>

Reads a single i16.

The provided endian specifies the byte order.

§Errors

If an error is returned, the chisel breaks.

Source

pub fn i32(&mut self, endian: Endianness) -> InfallibleFormatResult<i32, S>

Reads a single i32.

The provided endian specifies the byte order.

§Errors

If an error is returned, the chisel breaks.

Source

pub fn i64(&mut self, endian: Endianness) -> InfallibleFormatResult<i64, S>

Reads a single i64.

The provided endian specifies the byte order.

§Errors

If an error is returned, the chisel breaks.

Source

pub fn f32(&mut self, endian: Endianness) -> InfallibleFormatResult<f32, S>

Reads a single f32.

The provided endian specifies the byte order.

§Errors

If an error is returned, the chisel breaks.

Source

pub fn f64(&mut self, endian: Endianness) -> InfallibleFormatResult<f64, S>

Reads a single f64.

The provided endian specifies the byte order.

§Errors

If an error is returned, the chisel breaks.

Source

pub fn skip(&mut self, how_many: usize) -> InfallibleFormatResult<(), S>

Skips how_many bytes of the underlying source.

This is provided for optimization reasons. This hint is forwarded to the source.

Exactly how_many bytes are skipped, as-if read_buf were called with a buffer of appropriate size, with the buffer being discarded.

§Errors

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

If an error is returned, the chisel breaks.

Source

pub fn read_until( &mut self, delimiter: u8, dest: &mut Vec<u8>, ) -> InfallibleFormatResult<(), S>

Reads bytes into the provided dest Vec until the delimiter byte is encountered.

§Errors

If the end of the input is encountered before the delimiter is found, ChiselErrorData::EndOfInput is returned.

If an error is returned, the chisel breaks.

Source

pub fn read_until_or_end( &mut self, delimiter: u8, dest: &mut Vec<u8>, ) -> InfallibleFormatResult<ReadUntilStopReason, S>

Reads bytes into the provided dest Vec until the delimiter byte or end-of-input is encountered.

§Errors

If an error is returned, the chisel breaks.

Auto Trait Implementations§

§

impl<S> Freeze for Chisel<S>
where S: Freeze,

§

impl<S> RefUnwindSafe for Chisel<S>
where S: RefUnwindSafe,

§

impl<S> Send for Chisel<S>
where S: Send,

§

impl<S> Sync for Chisel<S>
where S: Sync,

§

impl<S> Unpin for Chisel<S>
where S: Unpin,

§

impl<S> UnwindSafe for Chisel<S>
where S: 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.