Struct AsyncParser

Source
pub struct AsyncParser<R>(/* private fields */);
Expand description

A wrapper for Parser.

AsyncParser reads from the reader into a buffer where Parser can parse the requested data. Every request for data will ask for exactly what’s needed to perform the task.

§Example

use futures::io::Cursor;

use mbon::async_wrapper::AsyncParser;

let reader = Cursor::new(b"i\x00\x00\x00\x0f");
let mut parser = AsyncParser::from(reader);

let val: u32 = parser.next().await?;

assert_eq!(val, 15);

Implementations§

Source§

impl<R> AsyncParser<R>
where R: AsyncReadExt + Unpin + Send,

Source

pub fn reader(self) -> R

Turn the parser into the underlying reader

Source

pub fn get_reader(&self) -> &R

Get the underlying reader as a reference

Source

pub fn get_reader_mut(&mut self) -> &mut R

Get the underlying reader as a mutable reference

Source

pub async fn next<T>(&mut self) -> Result<T>

Parse the next item in the parser.

Source

pub async fn next_obj<T>(&mut self) -> Result<T>
where T: ObjectParse, <T as ObjectParse>::Error: Error + 'static,

Parse the next custom object in the parser.

This allows you to be able to parse custom binary data. A common usecase is to store a struct in a more compact form. You could also use object values to store a different format altogether.

Note: the next value in the parser must be an Object

see Parser::next_obj()

Source

pub async fn skip_next(&mut self) -> Result<()>

Skip the next value in the parser.

This will ignore the next value without parsing more than what’s necessary.

If the reader supports seeking, then it is preffered to use seek_next() instead.

see Parser::skip_next()

Source

pub async fn next_value(&mut self) -> Result<Value>

Parse the next value in the parser.

see Parser::next_value()

Source§

impl<R> AsyncParser<R>

Source

pub async fn seek_next(&mut self) -> Result<()>

Seek to the next value in the parser.

This will efficiently skip the next value without reading more than what’s necessary

see Parser::seek_next()

Trait Implementations§

Source§

impl<R> AsMut<R> for AsyncParser<R>

Source§

fn as_mut(&mut self) -> &mut R

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl<R> AsRef<R> for AsyncParser<R>

Source§

fn as_ref(&self) -> &R

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<R: Debug> Debug for AsyncParser<R>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<R> From<R> for AsyncParser<R>
where R: AsyncReadExt + Unpin + Send,

Source§

fn from(reader: R) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<R> Freeze for AsyncParser<R>
where R: Freeze,

§

impl<R> RefUnwindSafe for AsyncParser<R>
where R: RefUnwindSafe,

§

impl<R> Send for AsyncParser<R>
where R: Send,

§

impl<R> Sync for AsyncParser<R>
where R: Sync,

§

impl<R> Unpin for AsyncParser<R>
where R: Unpin,

§

impl<R> UnwindSafe for AsyncParser<R>
where R: 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.