Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Extension with Rust

mimas is designed to live inside a Rust program, and the boundary between the two is meant to be easy to cross: Rust can provide its types, functions, and systems, mimas takes it from there. This chapter covers that boundary – how to expose your Rust code to mimas, what happens to values as they cross, and how to handle the things that can go wrong.

The short version is that a single attribute is usually all it takes:

// rust
#[mimas]
fn roll(sides: i64) -> i64 {
    /* ... */
}
// mimas
print(roll(20));

Nothing about this is dynamic: the signature you write in Rust becomes the signature the mimas compiler enforces at every call site, so a script that misuses your API fails to compile rather than failing at runtime.

PageCovers
BasicsThe mimas macro: functions, constants, types, and modules
Working With TypesHow Rust types map to mimas types, and what each costs
Runtime ErrorsThe ways a native function can fail, recoverably or not
Fixtures & ContextHow to communicate data from the host into the native functions you provide
FreezeTaking Fixtures a step further and enabling mutable access to the host.
Advanced UsageRegistering by hand for the cases the macro can’t infer