Module loader

Module loader 

Source
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:

  1. Async file open: Opens the 3MF file using tokio::fs::File::open()
  2. ZIP initialization: Creates an AsyncZipArchive and reads the central directory
  3. OPC relationship parsing: Reads _rels/.rels to find the main model part
  4. Async entry reading: Reads the model XML data from the archive
  5. 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.