Skip to main content

Module async_io

Module async_io 

Source
Expand description

Async I/O entry points — feature tokio.

The parser itself is synchronous and CPU-bound; async support here is the standard “slurp bytes via async I/O, then hand to the existing parser” pattern. It doesn’t parse incrementally across .await points — for that, use the streaming reader (crate::Iterparse / crate::XmlReader) on bytes you’ve already collected.

§Example

use sup_xml::async_io::parse_async;

// Any `tokio::io::AsyncRead` works — `tokio::fs::File` (under
// the `fs` tokio feature), a TCP stream, a `&[u8]` cursor, etc.
let bytes: &[u8] = b"<r><a>hi</a></r>";
let doc = parse_async(bytes).await?;
println!("root: {}", doc.root().name());

Bounded-memory usage: callers that don’t trust their input should wrap the reader in tokio::io::AsyncReadExt::take(MAX) before passing.

Functions§

parse_async
Read reader to end asynchronously, then parse the bytes. Uses default ParseOptions.
parse_async_with
Like parse_async but consults the supplied ParseOptions (e.g. recovery_mode: true, external_resolver: Some(...)).