Rust binding

Start with the module-specific guides for basic examples, common workflows, and binding limitations: PUQ, MAT, and DIP. This compatibility reference retains shared setup details and additional examples for existing links.

The Rust workspace in bindings/rust wraps the SNT3 C ABI. Parsing, validation, DIPH5 I/O, PUQ operations, MAT calculations, and value conversion remain in the C++ core. The scinumtools3-sys crate contains raw declarations; scinumtools3 owns the native handles and exposes Result-returning methods.

The Rust crate builds the bundled SNT3 C++ source automatically. Users need a C++17 compiler, CMake, and HDF5 development libraries, but do not need a separate SNT3 installation. To reuse a native installation, set SNT3_PREFIX to its prefix. In a source checkout, set SNT3_BUILD_DIR to an existing CMake build directory. HDF5 is linked through pkg-config or the environment variables described in bindings/rust/scinumtools3-sys/README.md.

cmake -S . -B build-rust -DENABLE_BINDING_C=ON \
    -DENABLE_BINDING_PYTHON=OFF -DENABLE_UNIT_TESTS=OFF \
    -DENABLE_EXEC_APPS=OFF -DENABLE_EXEC_EXAMPLES=OFF \
    -DENABLE_SNT_REPORT=OFF
cmake --build build-rust --target snt-c
SNT3_BUILD_DIR="$PWD/build-rust" cargo test --manifest-path bindings/rust/Cargo.toml

Project::load accepts a DIPfile, a directory containing one, a standalone .dip or .dipl source, or a .diph5 archive:

use scinumtools3::Project;

let project = Project::load("DIPfile")?;
let steps = project.node("simulation.steps")?.as_i64()?;
let samples = project.node("simulation.samples")?.as_i64_array()?;
println!("{steps}: {samples:?}");

The binding also provides read-only hierarchy traversal, units, metadata, provenance, overrides, DIPH5 saving, and comparison. Register sources and overrides before calling parse; create a new Project for a different configuration. The underlying C ABI is currently experimental, so the Rust binding retains 0.x compatibility expectations.

The mat module evaluates the same typed MAT records as the CLI and REST server. Results expose their canonical JSON through MatResult::json, which keeps every native field while avoiding an additional serialization dependency:

use scinumtools3::mat::{self, MatterInput};

let carbon = mat::element("C{13+2}")?.json()?;
let matter = MatterInput {
    mass_density: Some("1.02*g/cm3".into()),
    volume: Some("1*L".into()),
    ..Default::default()
};
let brine = mat::material_with(
    "0.965 <H2O> 0.035 <NaCl>", "mass_fraction", true, &matter,
)?.json()?;