Interop & Migration

Rust Interop

What Rust generation provides in v5.6, and what it does not make part of the Topaz language.

Rust is a lowering and native-build target, not embedded Topaz syntax. The checker resolves a complete Topaz unit first; the emitter then produces Rust against the shipped runtime closure. Users may inspect or integrate that artifact at a build boundary without writing Rust tokens in .tpz files.

Contract and components

Default emission uses the boxed backend. The native backend specializes statically proven scalar regions and falls back to boxed representation when necessary. emit --out-dir scaffolds a cargo-runnable crate; native build invokes cargo and can run the resulting program. The runtime closure is shipped with the compiler so no Topaz-specific installation is required on the target.

Workflow

Keep the source and public module API canonical Topaz. Run check, compare run, emit/build, then test the generated artifact with the same inputs and declared host profile. If a Rust service wraps the artifact, that wrapper is foreign code with a separate ownership, error, dependency, and security review.

Current support

The boxed and native Rust paths are tested against direct execution. Tests also compile generated crates and cover web runtime paths, checked arithmetic, module boundaries, faults, and cleanup behavior.

Boundaries and limitations

use crate::, ::, attributes, Rust references, Vec<T>, impl, Rust receiver syntax, and Rust closure tokens are forbidden in canonical Topaz. v5.6 does not promise source-level Rust FFI, stable generated-Rust internals, arbitrary host exception translation, or a safe wrapper merely because generated code compiles.

Command reference

topaz emit main.tpz
topaz emit main.tpz --out-dir generated-rust
topaz build main.tpz --out-dir native-build --run