Skip to main content

Skip

Trait Skip 

Source
pub trait Skip: Read {
    // Provided methods
    fn skip(&mut self, len: usize) -> Result<(), Error> { ... }
    fn remaining_input(&self) -> Option<usize> { ... }
}
Expand description

A trait that allows for efficient skipping forward while reading data.

Provided Methods§

Source

fn skip(&mut self, len: usize) -> Result<(), Error>

Advance the cursor by len bytes.

If possible, the implementation should be more efficient than calling Read::read and discarding the resulting bytes.

Calling skip with a len that advances the cursor past the end of the underlying data source is permissible. The only requirement is that the next call to Read::read indicates EOF.

§Errors

Can return an error in all the same cases that Read::read can.

TODO: Remove this clippy suppression when the issue is fixed. See https://github.com/rust-lang/rust-clippy/issues/12519

Source

fn remaining_input(&self) -> Option<usize>

An upper bound, if cheaply known, on the number of bytes still readable from this source. Used to reject an array/map block that claims more elements than the input could possibly contain: each element consumes at least zero bytes, so a block longer than the remaining input only happens when a small (or hostile) message claims a huge count, which would otherwise drive an unbounded Vec allocation (length amplification). Streaming sources that can’t answer cheaply return None.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementations on Foreign Types§

Source§

impl Skip for &[u8]

Source§

fn skip(&mut self, len: usize) -> Result<(), Error>

Source§

fn remaining_input(&self) -> Option<usize>

Source§

impl Skip for File

Source§

fn skip(&mut self, len: usize) -> Result<(), Error>

Source§

impl<R: Read> Skip for MultiGzDecoder<R>

Source§

impl<S: Skip + ?Sized> Skip for Box<S>

Source§

fn skip(&mut self, len: usize) -> Result<(), Error>

Source§

fn remaining_input(&self) -> Option<usize>

Source§

impl<T: AsRef<[u8]>> Skip for Cursor<T>

Source§

fn skip(&mut self, len: usize) -> Result<(), Error>

Source§

fn remaining_input(&self) -> Option<usize>

Implementors§