Expand description
High-level async 3MF model loading.
This module provides the load_model_async function, which orchestrates the complete
async loading pipeline from file path to parsed Model.
§Loading Pipeline
The function performs these steps:
- Async file open: Opens the 3MF file using
tokio::fs::File::open() - ZIP initialization: Creates an
AsyncZipArchiveand reads the central directory - OPC relationship parsing: Reads
_rels/.relsto find the main model part - Async entry reading: Reads the model XML data from the archive
- Spawn-blocked parsing: Offloads CPU-bound XML parsing to a blocking thread pool
§Performance Characteristics
- I/O operations: Non-blocking, multiple files can be loaded concurrently
- XML parsing: Runs on blocking thread pool via
tokio::task::spawn_blocking - Memory: Entire model XML is loaded into memory before parsing
§Examples
§Basic Usage
use lib3mf_async::loader::load_model_async;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let model = load_model_async("cube.3mf").await?;
println!("Loaded {} build items", model.build.items.len());
Ok(())
}§Concurrent Loading
use lib3mf_async::loader::load_model_async;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Load multiple files concurrently
let (model1, model2, model3) = tokio::try_join!(
load_model_async("file1.3mf"),
load_model_async("file2.3mf"),
load_model_async("file3.3mf"),
)?;
println!("Loaded {} models concurrently", 3);
Ok(())
}Functions§
- load_
model_ async - Asynchronously loads a 3MF model from a file path.