./rust is a small library; each one becomes a service you inject like any other. Every exported function returns a Promise and runs on a separate thread pool, so it never blocks the event loop.
You need a Rust toolchain (rustup) on the machines that build the app, and @orion-js/native in your dependencies.
Create a library
rust/ and app/rust/. rust/target is added to .gitignore.
Write Rust
#[model]structs become TypeScript interfaces. Field names are camelCased (created_at→createdAt),_idis kept andOption<T>fields are optional.#[export]functions become async functions on the library’s service.- Supported types:
String,bool,f64,f32, 32-bit and smaller integers,Option,Vec,HashMap<String, T>,DateTime(a JSDate),Bytes(aBuffer), and other models. 64-bit integers don’t fit in a JS number and are a compile error.
Use it from TypeScript
Errors
Large data
Top-levelVec<T> params and returns are sent in small frames, so 100k documents don’t pause the event loop. To read many Mongo documents, skip JS decoding entirely and pass raw BSON:
Libraries using each other
A library can depend on another one in itsCargo.toml (orders = { path = "../orders" }) and call it directly in Rust. Models are shared too: the generated TypeScript imports them from the other library’s file. Model names must be unique across libraries.
Commands
orion devcompiles./rustbefore starting and rebuilds on changes. A rebuild restarts the app.orion buildcompiles in release mode, fails ifapp/rustis out of date, and writesnative.nodenext to the bundle. Deploy them together.orion rust build [--release] [--check]compiles and updatesapp/rust. Use--checkin CI.orion rust new <name>creates a library.
ORION_NATIVE_THREADS).