Expand description
Async XML API. Async API for XML conversion with Tokio
This module provides asynchronous versions of all XML conversion functions, enabling high-performance concurrent I/O operations with Tokio.
§Features
- Async File I/O: Read/write XML files without blocking
- Async Streaming: Stream large XML files incrementally
- Concurrency: Process multiple files concurrently
- Backpressure: Built-in flow control for streaming
§Examples
§Async file conversion
use hedl_xml::async_api::{from_xml_file_async, to_xml_file_async};
use hedl_xml::{FromXmlConfig, ToXmlConfig};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Read XML file asynchronously
let doc = from_xml_file_async("input.xml", &FromXmlConfig::default()).await?;
// Process document...
// Write XML file asynchronously
to_xml_file_async(&doc, "output.xml", &ToXmlConfig::default()).await?;
Ok(())
}§Async streaming for large files
use hedl_xml::async_api::from_xml_stream_async;
use hedl_xml::streaming::StreamConfig;
use tokio::fs::File;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let file = File::open("large.xml").await?;
let config = StreamConfig::default();
let mut stream = from_xml_stream_async(file, &config).await?;
while let Some(result) = stream.next().await {
match result {
Ok(item) => println!("Processed: {}", item.key),
Err(e) => eprintln!("Error: {}", e),
}
}
Ok(())
}§Concurrent processing
use hedl_xml::async_api::from_xml_file_async;
use hedl_xml::FromXmlConfig;
use tokio::task;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = FromXmlConfig::default();
// Process multiple files concurrently
let handles: Vec<_> = vec!["file1.xml", "file2.xml", "file3.xml"]
.into_iter()
.map(|path| {
let config = config.clone();
task::spawn(async move {
from_xml_file_async(path, &config).await
})
})
.collect();
// Wait for all to complete
for handle in handles {
let doc = handle.await??;
// Process document...
}
Ok(())
}Structs§
- Async
XmlStream - Async streaming XML parser
Functions§
- from_
xml_ async - Parse XML string asynchronously (runs on tokio threadpool)
- from_
xml_ file_ async - Read and parse an XML file asynchronously
- from_
xml_ files_ concurrent - Process multiple XML files concurrently
- from_
xml_ reader_ async - Parse XML from an async reader
- from_
xml_ stream_ async - Create an async streaming XML parser
- to_
xml_ async - Convert HEDL to XML string asynchronously (runs on tokio threadpool)
- to_
xml_ file_ async - Write a HEDL document to an XML file asynchronously
- to_
xml_ files_ concurrent - Write multiple documents to XML files concurrently
- to_
xml_ writer_ async - Write XML to an async writer