More examples of Surrealism in practice can be seen inside the surrealism repo.
Surrealism Rust code demo
This demo contains examples of the #[surrealism] attribute in real code.
Renaming an export
You can rename a function on the SurrealDB side:
#[surrealism(name = "other")]
fn can_drive_bla(age: i64) -> bool {
age >= 18
}Setting a default export
You can make a function the default, allowing calls via the module path alone:
#[surrealism(default)]
fn def(age: i64) -> bool {
age >= 18
}Attaching export comments
#[surrealism(comment = "Parses a string into a number")]
fn parse_number(input: String) -> Result<i64, String> {
input.parse::<i64>().map_err(|e| e.to_string())
}CLI examples
This file shows ways to work with module archives directly from the CLI.
# Scaffold a new module project
surreal module init
# Build quickly while iterating
surreal module build --debug --out demo.surli .
# See function signature
surreal module sig --fnc can_drive demo.surli
# Run function with argument
surreal module run --fnc can_drive --arg 17 demo.surli