Struct mbon::async_wrapper::AsyncParser
source · pub struct AsyncParser<R>(_);
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
sourceimpl<R> AsyncParser<R>where
R: AsyncReadExt + Unpin + Send,
impl<R> AsyncParser<R>where
R: AsyncReadExt + Unpin + Send,
sourcepub fn get_reader(&self) -> &R
pub fn get_reader(&self) -> &R
Get the underlying reader as a reference
sourcepub fn get_reader_mut(&mut self) -> &mut R
pub fn get_reader_mut(&mut self) -> &mut R
Get the underlying reader as a mutable reference
sourcepub async fn next<T>(&mut self) -> Result<T>where
T: DeserializeOwned,
pub async fn next<T>(&mut self) -> Result<T>where
T: DeserializeOwned,
Parse the next item in the parser.
sourcepub async fn next_obj<T>(&mut self) -> Result<T>where
T: ObjectParse,
<T as ObjectParse>::Error: Error + 'static,
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
sourcepub async fn skip_next(&mut self) -> Result<()>
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.
sourcepub async fn next_value(&mut self) -> Result<Value>
pub async fn next_value(&mut self) -> Result<Value>
Parse the next value in the parser.