Functions
fn add(left: i64, right: i64) -> i64 {
left + right
}
fn absolute(value: i64) -> i64 {
if value < 0 { ret -value }
value
}
Parameters are typed. A final expression is the result; early return uses
ret, not return. Omitting -> means void.
Methods and destructors
struct counter { value: i64 }
@borrow
fn counter.current() -> i64 {
self.value
}
fn counter.drop() {
// consuming implicit self
}
self is implicit and must not appear in the parameter list. @borrow gives a
shared lexical receiver loan. A destructor consumes its owner and runs exactly
once on structured cleanup unless the value was moved or manually dropped.
Generics and traits
trait identity {
fn id() -> i64
}
fn identify<t: identity>(value: t) -> i64 {
value.id()
}
Generic parameters and trait/type names use lower snake case. Implementations are checked for completeness, signature match, coherence, and orphan rules. Dispatch is statically monomorphized without vtables or hidden allocation.
Foreign functions
extern "c" fn platform_call(value: i64) -> i64 link_name "platform_call";
Foreign calls require unsafe until wrapped by an audited safe function. ABI,
effects, ownership, and platform availability belong in the wrapper and .sdi
contract.
Function values, closures, and tasks
Function values and indirect calls preserve parameter/return ownership,
effects, and linear t contracts. A closure uses |parameters| body or
|| body; contextual fn(...) -> t types may infer its parameter types.
Plain closures are allocation-free and non-escaping. Their captures copy or
move by capability, remain immutable, and clean exactly once. Use
box |parameters| body for an escaping retained callback; construction returns
result<box fn(...) -> t, alloc_error>. Boxed callbacks are move-only,
non-cloneable, non-sendable, and cannot escape an active region.
Seed callable values carry code/environment descriptors. C/platform function pointers remain thin and accept named functions only. Recursive closures and capture by reference are unsupported.
spawn { ... } outlines a void task body; handle option/result failures
inside it because ? cannot cross the task boundary.