Skip to main content

Module tokio_async

Module tokio_async 

Source
Expand description

Native async YAML parsing for tokio runtimes — from_async_reader plus a tokio_util::codec::Decoder. Gated by the tokio feature. Native async YAML parsing for tokio runtimes.

Bridges noyalib’s strict-parser entry points (crate::from_str, crate::from_slice) onto tokio::io::AsyncRead sources without forcing the caller through tokio::task::spawn_blocking. Two surface shapes are provided so callers can pick the right ergonomics for their workload:

  • from_async_reader — drain a single document out of any tokio::io::AsyncRead into the caller’s T.
  • from_async_reader_multi — drain every ----separated document and return Vec<T>.
  • AsyncYamlStream: a backpressured Stream of parsed documents, constructed with async_yaml_stream or async_yaml_stream_with_config.
  • YamlDecoder: the lower-level tokio_util::codec::Decoder used by the stream surface and available for custom framed pipelines.

§Backpressure

The from_async_reader entry points buffer the full payload into a Vec<u8> before parsing because the underlying parser is synchronous. The codec surface is the streaming choice: it emits one document per decode call as soon as a complete --- boundary is in the buffer.

Gated behind the tokio Cargo feature (which transitively enables tokio-util and bytes for the codec API).

§Example

use tokio::io::BufReader;
let bytes: &[u8] = b"name: noyalib\nversion: 0.0.6\n";
let mut reader = BufReader::new(bytes);
#[derive(serde::Deserialize)]
struct Pkg { name: String, version: String }
let pkg: Pkg = noyalib::tokio_async::from_async_reader(&mut reader).await?;
assert_eq!(pkg.name, "noyalib");

Structs§

YamlDecoder
[tokio_util::codec::Decoder] that emits one parsed T per ----delimited YAML document in the byte stream.

Functions§

async_yaml_stream
Wrap an asynchronous reader as a backpressured YAML document stream.
async_yaml_stream_with_config
Wrap an asynchronous reader as a backpressured YAML document stream with caller-supplied parser limits and policies.
from_async_reader
Drain the supplied reader to end-of-stream, then parse the buffered bytes as a single YAML document into T.
from_async_reader_multi
Drain the reader and parse every ----separated document into Vec<T> using the default ParserConfig.
from_async_reader_multi_with_config
from_async_reader_multi with a caller-supplied ParserConfig. The reader is bounded by ParserConfig::max_stream_bytes. Every split document is then bounded independently by ParserConfig::max_document_length.
from_async_reader_with_config
from_async_reader with a caller-supplied ParserConfig.

Type Aliases§

AsyncYamlStream
A backpressured asynchronous stream of YAML documents.