Rust API
Open the Rust API documentation to browse types, functions, examples, and signatures with rustdoc navigation and search.
The reference includes all optional features. Enable the features and install the native dependencies needed by your application; see the Rust setup guide.
View sourceCompile and inspect a model
Section titled “Compile and inspect a model”Add eqiora to a Cargo project as described in the setup guide above,
then put this in src/main.rs and run cargo run:
use eqiora::api::ModelDocument;use eqiora::kernel::KernelNode;use eqiora::language::NotationProfile;
fn main() { let model = ModelDocument::compile("decay.eqi", r#" model decay(parameter rate: 1 / s = 1) { state x: 1; initial { x = 1; } relation flow { derivative(x) + rate * x = 0; } } "#).expect("model must compile");
for node in model.program().nodes() { if let KernelNode::Relation(relation) = node { let equations = model.render_equations( relation.id().into(), NotationProfile::Plain, ).expect("equations must render"); for equation in equations { println!("{}", equation.text()); } } }}Compilation checks names and dimensions and produces an immutable Model; the program then prints its equations. Nothing is simulated here. To resolve and run a model, see the Python workflow.
Work with physical quantities
Section titled “Work with physical quantities”use eqiora::aliases::Velocity;
let inlet = Velocity::new(3.0);let correction = Velocity::new(0.5);println!("{} m/s", (inlet + correction).value());The result is 3.5 m/s. Quantities carry their dimension in the Rust
type; adding a velocity to a length is a type error. Values use SI units.
Save and reload a Model
Section titled “Save and reload a Model”Continue with the compiled model from the first example:
let bytes = model.canonical_json().expect("model must serialize");std::fs::write("decay.model.json", &bytes).expect("file must be writable");let restored = ModelDocument::replay(&bytes).expect("model must reload");assert!(model.structurally_equivalent(&restored).unwrap());Replay restores the model’s mathematical content but not its source text, so
keep the original .eqi file if you want to edit or display the source.
Modules
Section titled “Modules”Choose a module below, then use rustdoc’s search to find a type or method.