Rust
The safe scinumtools3 Rust crate does not currently expose a standalone
puq module or Quantity type. PUQ expressions are accepted as strings
where DIP and MAT need dimensional values.
Basic examples
Read a dimensional value through DIP using the scinumtools3 crate:
use scinumtools3::Project;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut project = Project::new()?;
project.add_source("distance float = 2.5 m")?;
project.parse()?;
let distance = project.node("distance")?;
println!("{} {}", distance.as_f64()?, distance.units()?.unwrap_or_default());
Ok(())
}
Supply PUQ expressions as MAT matter inputs:
use scinumtools3::mat::{self, MatterInput};
fn main() -> Result<(), Box<dyn std::error::Error>> {
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,
)?;
println!("{}", brine.json()?);
Ok(())
}
Common workflows
Task |
Call chain |
Result |
|---|---|---|
Read a DIPL value with units |
|
|
Supply MAT matter inputs |
|
|
Serialize a MAT result |
|
|
Use direct PUQ |
|
Raw C ABI handles and status codes |
use scinumtools3::{mat, Project};
let mut project = Project::new()?; // Project
project.add_source("distance float = 2.5 m")?;
project.parse()?; // ()
let distance = project.node("distance")?; // Node<'_>
let value = distance.as_f64()?; // f64
let units = distance.units()?; // Option<String>
let result = mat::substance("H2O")?; // MatResult
let json = result.json()?; // String
Use the C ABI through scinumtools3-sys when direct PUQ access is required,
or the CLI, C++, or Python interfaces for the complete PUQ surface.
For direct PUQ access from Rust, use the experimental C ABI through
scinumtools3-sys. See the Rust binding guide for the crate layout and build requirements.
Current limitations and differences
Compared with the canonical C++ implementation:
The safe crate has no standalone
Quantitytype, arithmetic, conversion, uncertainty sampling, or unit-system context API.DIP values and MAT matter inputs accept dimensional expressions as strings. Reading a DIP value returns its numerical value and units separately.
Direct PUQ calls require the unsafe
scinumtools3-syslayer, which has the same coverage limits as the C ABI. Use C++ or Python for native quantity operations.
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. Option<T> means the value may be absent; Result<T> means the
call can fail. The Rust binding guide documents the crate layout and build
requirements.
MAT matter inputs use the string fields on
mat::MatterInput:number_density,mass_density,volume, andmass.Project::node(path)?.units()?returns a DIPL value’s unit expression.Raw PUQ C ABI calls are available through
scinumtools3-sys; the safe crate does not wrapsnt_puq_quantity_eval,convert, orformat.There are no safe Rust counterparts for
Quantityarithmetic, uncertainty sampling, unit-system contexts, or PUQ listing functions.