Rust
The Rust crate is trigora in trigora-rust. It authors Programs. The CLI compiles and deploys them. The client is trigora-client.
use trigora::{effect, wait_for_event};
pub struct Approval { pub result: f64, pub review: bool,}
pub async fn main() -> Result<Approval, String> { let amount: f64 = 42.0; let result = effect("generate", move || amount).await?; let review: bool = wait_for_event("approved").await?; Ok(Approval { result, review })}Point trigora.toml at the crate sources:
[project]name = "approval"programs = ["src/**/*.rs"]Rust Program ids use the source file stem. For lib.rs and main.rs, the Cargo package name is used instead. The artifact function name is main.
Supported syntax
Section titled “Supported syntax”- One
pub async fn mainwith plain owned parameters. Exact arity, no defaults. It returnsResult. See Programs. effect,sleep,invoke,join,race, andwait_for_event. All are awaited. Names are string literals.- Ordinary computation between durable operations, including structs, enums,
Option,Result,Vec,if,loop,while,for, andmoveclosures. Numbers use thef64domain. Helper functions cannot await. join(left, right)andrace(left, right), which provide the same durable join semantics asPromise.all/gatherandPromise.race/race. The Rust frontend accepts exactly two branches; the engine supports groups of 1–32 branches. See Structured concurrency.
use trigora::{effect, invoke, join, race, sleep};
pub async fn main(topic: String) -> Result<(), String> { let report: String = effect("research", move || topic).await?; let _notes: String = invoke("summarize", report).await?; let pair = join( effect("left", || 1.0), effect("right", || 2.0), ).await?; let _winner: f64 = race( effect("fast", || 1.0), effect("slow", || 2.0), ).await?; let _ = pair.len(); let _ = sleep(60_000.0).await?; Ok(())}invoke("child", value) is a one-element vector. invoke("child", (a, b)) is two arguments. invoke("child", ()) is empty.
An effect closure that captures values must use move. Each captured value is stored under its binding name, and the host runs the effect body when the durable operation is dispatched.
Unsupported syntax
Section titled “Unsupported syntax”- A second
pub async fn main, a missing argument, or an extra argument. &and&mutin user code, integer types other than thef64domain, traits, macros, and async helpers.- Calling
mainyourself. Usetrigora devor Cloud.
See Rust SDK and Supported language semantics.