Rust

Project wraps the C ABI and returns Result values.

Basic examples

Parse text with the scinumtools3 crate and read a typed value:

use scinumtools3::Project;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut project = Project::new()?;
    project.add_source("simulation.steps int = 100")?;
    project.parse()?;
    println!("{}", project.node("simulation.steps")?.as_i64()?);  // 100
    Ok(())
}

Apply an override before evaluating a new project:

use scinumtools3::Project;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut project = Project::new()?;
    project.add_source("simulation.steps int = 100")?;
    project.add_override("simulation.steps = 200")?;
    project.parse()?;
    println!("{}", project.node("simulation.steps")?.as_i64()?);  // 200
    Ok(())
}

Common workflows

Task

Call chain

Result

Create an empty project

Project::new()

Result<Project>

Load an artifact

Project::load(path)

Result<Project>

Compose a project

add_source, add_file, add_project, add_schema, add_override

Result<()>

Evaluate

parse()

Result<()>

Read a known value

node(path); as_i64, as_f64, as_string, …

Node<'_>; typed Result<T>

Read a collection

as_i64_array and the other as_*_array methods; entries

Vec<T>; child nodes

Persist or compare

save(path); compare_diph5(before, after)

DIPH5 file; Comparison

Release resources

Drop the node and project

Automatic; no manual free function

use scinumtools3::{compare_diph5, Project};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut project = Project::new()?;                 // Project
    project.add_source(
        "simulation.steps int = 100\nsimulation.samples int[3] = [1, 2, 3]",
    )?;                                                // ()
    project.add_override("simulation.steps = 200")?;
    project.parse()?;                                  // ()

    let steps = project.node("simulation.steps")?;     // Node<'_>
    println!("{}", steps.as_i64()?);                   // i64
    println!("{:?}", project.node("simulation.samples")?.as_i64_array()?);

    project.save("run.diph5")?;
    let changes = compare_diph5("before.diph5", "run.diph5")?;
    println!("{} changed", changes.changed);
    Ok(())
}

Register sources, schemas, and overrides before parse(). A project cannot be reconfigured after evaluation; create a new Project instead. Nodes borrow their project and must not outlive it. Native handles are released by Rust’s Drop implementation, including on error.

See the Rust binding guide for overrides, persistence, and comparison.

DIPL developer tools. Rust parsing validates the DIPL model and returns an error for invalid input. Use format_dip_source and format_dip_file to apply the native DIPL formatter; file formatting reads the nearest DIPfile’s format settings. The crate does not currently wrap the standalone validator or linter; use snt dip validate and snt dip lint when those results are needed. See the DIPL developer tools page for the CLI workflow.

Current limitations and differences

Compared with the canonical C++ implementation:

  • The safe crate wraps a subset of the C ABI. It has no native Inspector or semantic preview API, host callbacks, adapters, report/export helpers, editing sessions, guided setup, or experiment lifecycle.

  • A Project is evaluated once. Register sources and overrides before parse() and create a new Project to evaluate a different configuration. Node handles borrow that project.

  • The standalone validator and linter are not wrapped. Parsing validates the input; use snt dip validate and snt dip lint for those checks.

Binding reference

This is a lookup index, not a sequence to read from top to bottom. Use Common workflows above to choose a task, then find the exact Rust name below. Result<T> means the call can fail; properties are shown without parentheses and callable names include their arguments.

Project lifecycle

  • Project::new() and Project::load(path).

  • add_source(source), add_file(path), and add_project(path).

  • add_schema(name, body) and add_override(body).

  • parse(), node(path), save(path), and source_files().

Node access

  • path(), kind(), value_type(), and shape().

  • as_bool(), as_i64(), as_u64(), as_f64(), and as_string().

  • as_bool_array(), as_i64_array(), as_u64_array(), as_f64_array(), and as_string_array().

  • units(), metadata(name), provenance(), and is_overridden().

  • len(), is_empty(), value_len(), and entries().

Comparison

  • compare_diph5(before, after) returns Comparison with added, removed, changed, and differences.

  • Difference exposes path, category, kind, fields, before, after, changed_elements, and example_indices.

Formatting

  • format_dip_source(source, options) formats text with FormatOptions.

  • format_dip_file(path) uses the nearest DIPfile’s format settings.