Skip to main content

Decoder

Trait Decoder 

Source
pub trait Decoder: Sized {
    // Required methods
    fn decode_byte(&mut self) -> Result<u8, DecodeError>;
    fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), DecodeError>;

    // Provided methods
    fn decode_ranged<T: Decode + PartialOrd>(
        &mut self,
        range: impl RangeBounds<T>,
    ) -> Result<T, DecodeError> { ... }
    fn assert_magic(&mut self) -> Result<(), DecodeError> { ... }
    fn decode<T: Decode>(&mut self) -> Result<T, DecodeError> { ... }
    fn decode_trailing<T: Decode>(&mut self) -> Result<Option<T>, DecodeError> { ... }
    fn decode_in<T: DecodeIn<A>, A: Allocator>(
        &mut self,
        alloc: A,
    ) -> Result<T, DecodeError> { ... }
}
Expand description

Helper trait for reading OpenTimestamps primitives from a byte stream.

Required Methods§

Source

fn decode_byte(&mut self) -> Result<u8, DecodeError>

Decodes a single byte from the reader.

Source

fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), DecodeError>

Provided Methods§

Source

fn decode_ranged<T: Decode + PartialOrd>( &mut self, range: impl RangeBounds<T>, ) -> Result<T, DecodeError>

Decodes a value and ensures it falls within the supplied range.

Source

fn assert_magic(&mut self) -> Result<(), DecodeError>

Verifies that the next bytes in the stream match the magic sequence.

Source

fn decode<T: Decode>(&mut self) -> Result<T, DecodeError>

Decodes a value implementing the Decode trait.

Source

fn decode_trailing<T: Decode>(&mut self) -> Result<Option<T>, DecodeError>

Decodes a trailing optional value implementing the Decode trait.

See Decode::decode_trailing for details and caveats.

Source

fn decode_in<T: DecodeIn<A>, A: Allocator>( &mut self, alloc: A, ) -> Result<T, DecodeError>

Decodes a value implementing the Decode trait.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl Decoder for &[u8]

Source§

fn decode_byte(&mut self) -> Result<u8, DecodeError>

Source§

fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), DecodeError>

Implementors§

Source§

impl<R: Read> Decoder for Reader<R>