AsyncReader

Type Alias AsyncReader 

Source
pub type AsyncReader<T> = GenericAsyncReader<T, Parser>;
Available on crate feature tokio only.
Expand description

§Tokio-compatible asynchronous restricted XML 1.0 parser

The AsyncReader allows parsing XML documents from a tokio::io::AsyncBufRead, asynchronously. It operates similarly as the Reader does, but it works with asynchronous data sources instead of synchronous (blocking) ones.

As it bases on Parser (instead of RawParser), namespace prefixes are resolved by the parser and attributes are collected in a map before they are handed to the application. If you do not need XML namespace support and can tolerate the caveats of the RawParser (see its documentation for details), AsyncRawReader may be a more suitable type for you.

Events can be obtained through read and read_all. If the stream feature is enabled, AsyncReader also implements the Stream trait.

§Example

The example is a bit pointless because it does not really demonstrate the asynchronicity.

use rxml::{AsyncReader, Error, Event, XmlVersion};
use tokio::io::AsyncRead;
let mut doc = &b"<?xml version='1.0'?><hello>World!</hello>"[..];
// this converts the doc into an tokio::io::AsyncRead
let mut pp = AsyncReader::new(&mut doc);
// we expect the first event to be the XML declaration
let ev = pp.read().await;
assert!(matches!(ev.unwrap().unwrap(), Event::XmlDeclaration(_, XmlVersion::V1_0)));

Aliased Type§

pub struct AsyncReader<T> { /* private fields */ }