Start: Library
To use Rimu in your Rust (opens in a new tab) app, add rimu
to your Cargo.toml
rimu = "*"
Rust
Rimu values can be serialized into any Rust struct, using serde
.
Here's an example:
// populate your pre-defined environment (context where variables are defined)
let env = Environment::new();
let env = Rc::new(RefCell::new(env));
// parse code into Rimu ast
let (block, errors) = rimu::parse(code, source_id);
let Some(block) = block else {
panic!("parse error")
}
// evaluate Rimu ast into Rimu value
let Ok(value) = rimu::evaluate(&block, env) else {
panic!("eval error")
}
let value: rimu::Value = value.inner();
let value: rimu::SerdeValue = value.into();
// serialize Rimu value into your Rust struct
let thing: YourThing = rimu::from_serde_value(value).unwrap();
Wasm
Rimu can also be compiled into a Wasm module with wasm-pack
(opens in a new tab), to be used in a web app.
See the playground code for ideas: rimu/play/wasm/src/lib.rs
(opens in a new tab)