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

Assura Quick Reference

Types

RustAssuraNotes
i8..i128, isizeIntArbitrary-precision signed
u8..u128, usizeNatNon-negative integer
f32, f64FloatIEEE 754
boolBool
String, &strStringUTF-8
Vec<u8>, &[u8]BytesByte buffer
()Unit
!, InfallibleNever
Vec<T>List<T>
HashMap<K,V>Map<K,V>
HashSet<T>Set<T>
Option<T>T?Nullable
Result<T,E>Result<T,E>Kept as-is
Box<T>, Arc<T>, Rc<T>TWrapper erased
&T, &mut TTReference erased
(A, B, C)(A, B, C)Tuples preserved

Refinement Types

x: Int where x > 0           // inline refinement
x: { n: Int | n >= 0 }       // set-builder syntax
data: NonEmpty<List<Int>>     // named refinement

Declaration Forms

Contract (standalone specification)

contract SafeDivision {
  input(a: Int, b: Int)
  output(result: Int)
  requires { b != 0 }
  ensures  { result * b + (a mod b) == a }
  effects  { pure }
}

Bind (attach contract to existing Rust function)

bind "mylib::divide" as divide_checked {
  input(a: Int, b: Int)
  output(result: Int)
  requires { b != 0 }
  ensures  { result == a / b }
}

Function

fn helper(x: Int) -> Bool
  requires { x >= 0 }
  ensures  { result == (x mod 2 == 0) }

Service (typestate)

service Connection {
  states { Disconnected, Connected, Authenticated }
  transitions {
    connect: Disconnected -> Connected
    login:   Connected -> Authenticated
    close:   * -> Disconnected
  }
}

Other declarations

type Percentage = { n: Float | n >= 0.0 && n <= 100.0 }
enum Status { Active, Inactive, Suspended }
extern fn system_time() -> Nat effects { time }
block incremental { ... }

Contract Clauses

ClausePurposeExample
requiresPreconditionrequires { x > 0 }
ensuresPostconditionensures { result >= 0 }
invariantLoop/type invariantinvariant { len >= 0 }
decreasesTermination measuredecreases { n }
effectsSide effect declarationeffects { io, database }
whereType constraintwhere T: Comparable
modifiesFrame conditionmodifies { buffer, count }
data_flowTaint/info-flow ruledata_flow { input must_not_reach output }

Expression Builtins

ExpressionMeaning
old(x)Value of x before function call
resultReturn value (in ensures)
forall x: T, P(x)Universal quantifier
exists x: T, P(x)Existential quantifier
abs(x)Absolute value
length(xs)Collection length
consumed(r)Linear resource consumed

Operator Precedence (low to high)

LevelOperators
1|| (logical or)
3&& (logical and)
5==, != (equality)
7<, >, <=, >= (comparison)
9+, - (additive)
11*, /, %, mod (multiplicative)
!, - (unary prefix)
., (), [] (postfix)

Effect Names

Group effects (expand to sub-effects)

GroupSub-effects
ioconsole.read, console.write, filesystem.read, filesystem.write, network.connect, network.send, network.receive, time.read, random
databasedatabase.read, database.write
logginglog.debug, log.info, log.warn, log.error

Short aliases

mem, net, fs, rng, time, alloc, diverge, random

Pure functions

effects { pure }   // no side effects allowed

Custom sub-effects

Any group.sub where group is known is accepted: io.custom, database.migrate.

Error Code Ranges

RangeCategoryExample
A01xxxSyntaxA01001 unexpected token
A02xxxName resolutionA02001 undefined symbol
A03xxxTypesA03001 type mismatch
A05xxxLinearityA05001 double use
A06xxxTypestateA06001 invalid transition
A07xxxEffectsA07001 undeclared effect
A08xxxInfo-flowA08001 taint leak

Look up any code: assura explain A03001

CLI Commands

assura check file.assura          # verify (parse + resolve + types + SMT)
assura check file.assura --watch  # re-verify on save
assura build file.assura          # verify + generate Rust code
assura init my-project            # scaffold new project
assura fmt file.assura            # format source
assura fmt file.assura --check    # check formatting (CI)
assura explain A03001             # explain error code
assura infer src/lib.rs           # generate bind skeletons from Rust
assura test-gen file.assura       # generate proptest code
assura audit .                    # scan Rust project for violations
assura coverage .                 # show contract coverage
assura doctor                     # check dependencies
assura agent-instructions         # AI agent quick reference
assura completions zsh            # generate shell completions

Common Patterns

// Safe division
requires { divisor != 0 }

// Bounds check
requires { index >= 0 && index < length(data) }

// Non-empty input
requires { length(items) > 0 }

// Monotonicity
ensures { result >= old(counter) }

// Size preservation
ensures { length(result) == length(input) }