Skip to content
Trigora
Start building →

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.

  • One pub async fn main with plain owned parameters. Exact arity, no defaults. It returns Result. See Programs.
  • effect, sleep, invoke, join, race, and wait_for_event. All are awaited. Names are string literals.
  • Ordinary computation between durable operations, including structs, enums, Option, Result, Vec, if, loop, while, for, and move closures. Numbers use the f64 domain. Helper functions cannot await.
  • join(left, right) and race(left, right), which provide the same durable join semantics as Promise.all / gather and Promise.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.

  • A second pub async fn main, a missing argument, or an extra argument.
  • & and &mut in user code, integer types other than the f64 domain, traits, macros, and async helpers.
  • Calling main yourself. Use trigora dev or Cloud.

See Rust SDK and Supported language semantics.