Skip to main content

LazyDecoder

Struct LazyDecoder 

Source
pub struct LazyDecoder<'a> { /* private fields */ }
Expand description

A decoder that only consumes bytes CHUNK_SIZE at a time. Useful to decode large files while maintaining memory usage low.

The decoder keeps an internal state with the bytes that have been read but not consumed, and a handle to a source that implements std::io::Read.

See Self::from_file for example, to lazily read and decode from a (large) file.

Implementations§

Source§

impl<'a> LazyDecoder<'a>

Source

pub fn from_file(file: &'a mut File) -> LazyDecoder<'a>

Source

pub fn skip(&mut self) -> Result<(), Box<dyn Error>>

Consumes enough bytes and skip the next CBOR element.

Source

pub fn decode<T>(&mut self) -> Result<T, Box<dyn Error>>
where T: for<'d> Decode<'d, ()>,

Consumes enough bytes and decode the next CBOR element.

Source

pub fn with_decoder<T>( &mut self, decode: impl Fn(&mut Decoder<'_>) -> Result<T, Box<dyn Error>>, ) -> Result<T, Box<dyn Error>>

Decode some element according to a custom strategy. This consumes more bytes if the decoder fails due to a lack of bytes. And error otherwise.

Auto Trait Implementations§

§

impl<'a> Freeze for LazyDecoder<'a>

§

impl<'a> !RefUnwindSafe for LazyDecoder<'a>

§

impl<'a> !Send for LazyDecoder<'a>

§

impl<'a> !Sync for LazyDecoder<'a>

§

impl<'a> Unpin for LazyDecoder<'a>

§

impl<'a> UnsafeUnpin for LazyDecoder<'a>

§

impl<'a> !UnwindSafe for LazyDecoder<'a>

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.