Reader

Trait Reader 

Source
pub trait Reader<'de>: Sealed {
    type Mut<'this>: Reader<'de>
       where Self: 'this;
    type TryClone: Reader<'de>;

    // Required methods
    fn borrow_mut(&mut self) -> Self::Mut<'_>;
    fn try_clone(&self) -> Option<Self::TryClone>;
    fn is_eof(&mut self) -> bool;
    fn skip<C>(&mut self, cx: C, n: usize) -> Result<(), C::Error>
       where C: Context;
    fn peek(&mut self) -> Option<u8>;
    fn read_bytes<C, V>(
        &mut self,
        cx: C,
        n: usize,
        visitor: V,
    ) -> Result<V::Ok, V::Error>
       where C: Context,
             V: UnsizedVisitor<'de, C, [u8], Error = C::Error, Allocator = C::Allocator>;
    unsafe fn read_bytes_uninit<C>(
        &mut self,
        cx: C,
        ptr: *mut u8,
        len: usize,
    ) -> Result<(), C::Error>
       where C: Context;

    // Provided methods
    fn read<C>(&mut self, cx: C, buf: &mut [u8]) -> Result<(), C::Error>
       where C: Context { ... }
    fn read_byte<C>(&mut self, cx: C) -> Result<u8, C::Error>
       where C: Context { ... }
    fn read_array<C, const N: usize>(
        &mut self,
        cx: C,
    ) -> Result<[u8; N], C::Error>
       where C: Context { ... }
    fn limit(self, limit: usize) -> Limit<Self>
       where Self: Sized { ... }
}
Expand description

Trait governing how a source of bytes is read.

This requires the reader to be able to hand out contiguous references to the byte source through Reader::read_bytes.

Required Associated Types§

Source

type Mut<'this>: Reader<'de> where Self: 'this

Type borrowed from self.

Why oh why would we want to do this over having a simple &'this mut T?

We want to avoid recursive types, which will blow up the compiler. And the above is a typical example of when that can go wrong. This ensures that each call to borrow_mut dereferences the Reader at each step to avoid constructing a large muted type, like &mut &mut &mut SliceReader<'de>.

Source

type TryClone: Reader<'de>

Type that can be cloned from the reader.

Required Methods§

Source

fn borrow_mut(&mut self) -> Self::Mut<'_>

Borrow the current reader.

Source

fn try_clone(&self) -> Option<Self::TryClone>

Try to clone the reader.

Source

fn is_eof(&mut self) -> bool

Test if the reader is at end of input.

Source

fn skip<C>(&mut self, cx: C, n: usize) -> Result<(), C::Error>
where C: Context,

Skip over the given number of bytes.

Source

fn peek(&mut self) -> Option<u8>

Peek the next value.

Source

fn read_bytes<C, V>( &mut self, cx: C, n: usize, visitor: V, ) -> Result<V::Ok, V::Error>
where C: Context, V: UnsizedVisitor<'de, C, [u8], Error = C::Error, Allocator = C::Allocator>,

Read a slice out of the current reader.

Source

unsafe fn read_bytes_uninit<C>( &mut self, cx: C, ptr: *mut u8, len: usize, ) -> Result<(), C::Error>
where C: Context,

Read into the given buffer which might not have been initialized.

§Safety

The caller must ensure that the buffer points to valid memory of length len.

Provided Methods§

Source

fn read<C>(&mut self, cx: C, buf: &mut [u8]) -> Result<(), C::Error>
where C: Context,

Read a slice into the given buffer.

Source

fn read_byte<C>(&mut self, cx: C) -> Result<u8, C::Error>
where C: Context,

Read a single byte.

Source

fn read_array<C, const N: usize>(&mut self, cx: C) -> Result<[u8; N], C::Error>
where C: Context,

Read an array out of the current reader.

Source

fn limit(self, limit: usize) -> Limit<Self>
where Self: Sized,

Keep an accurate record of the position within the reader.

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<'de> Reader<'de> for &'de [u8]

Source§

type Mut<'this> = &'this mut &'de [u8] where Self: 'this

Source§

type TryClone = &'de [u8]

Source§

fn borrow_mut(&mut self) -> Self::Mut<'_>

Source§

fn try_clone(&self) -> Option<Self::TryClone>

Source§

fn is_eof(&mut self) -> bool

Source§

fn skip<C>(&mut self, cx: C, n: usize) -> Result<(), C::Error>
where C: Context,

Source§

fn read<C>(&mut self, cx: C, buf: &mut [u8]) -> Result<(), C::Error>
where C: Context,

Source§

fn read_bytes<C, V>( &mut self, cx: C, n: usize, visitor: V, ) -> Result<V::Ok, V::Error>
where C: Context, V: UnsizedVisitor<'de, C, [u8], Error = C::Error, Allocator = C::Allocator>,

Source§

unsafe fn read_bytes_uninit<C>( &mut self, cx: C, ptr: *mut u8, n: usize, ) -> Result<(), C::Error>
where C: Context,

Source§

fn read_byte<C>(&mut self, cx: C) -> Result<u8, C::Error>
where C: Context,

Source§

fn read_array<C, const N: usize>(&mut self, cx: C) -> Result<[u8; N], C::Error>
where C: Context,

Source§

fn peek(&mut self) -> Option<u8>

Source§

impl<'de, R> Reader<'de> for &mut R
where R: ?Sized + Reader<'de>,

Source§

type Mut<'this> = &'this mut R where Self: 'this

Source§

type TryClone = <R as Reader<'de>>::TryClone

Source§

fn borrow_mut(&mut self) -> Self::Mut<'_>

Source§

fn try_clone(&self) -> Option<Self::TryClone>

Source§

fn is_eof(&mut self) -> bool

Source§

fn skip<C>(&mut self, cx: C, n: usize) -> Result<(), C::Error>
where C: Context,

Source§

fn read_bytes<C, V>( &mut self, cx: C, n: usize, visitor: V, ) -> Result<V::Ok, V::Error>
where C: Context, V: UnsizedVisitor<'de, C, [u8], Error = C::Error, Allocator = C::Allocator>,

Source§

unsafe fn read_bytes_uninit<C>( &mut self, cx: C, ptr: *mut u8, n: usize, ) -> Result<(), C::Error>
where C: Context,

Source§

fn peek(&mut self) -> Option<u8>

Source§

fn read<C>(&mut self, cx: C, buf: &mut [u8]) -> Result<(), C::Error>
where C: Context,

Source§

fn read_byte<C>(&mut self, cx: C) -> Result<u8, C::Error>
where C: Context,

Source§

fn read_array<C, const N: usize>(&mut self, cx: C) -> Result<[u8; N], C::Error>
where C: Context,

Implementors§

Source§

impl<'de> Reader<'de> for SliceReader<'de>

Source§

type Mut<'this> = &'this mut SliceReader<'de> where Self: 'this

Source§

type TryClone = SliceReader<'de>

Source§

impl<'de, R> Reader<'de> for Limit<R>
where R: Reader<'de>,

Source§

type Mut<'this> = &'this mut Limit<R> where Self: 'this

Source§

type TryClone = Limit<<R as Reader<'de>>::TryClone>