Skip to content

std/prelude ​

Imported into every program automatically (--no-prelude turns it off): the Error interface, Unit, and the error types that ? and .context() build. It also imports std/string's ASCII helpers, which is why those need no import.

API reference ​

Error ​

milo
pub interface Error

The structural error interface. Any type with message(self: &Self): string satisfies it, so a fn can return Result<T, Heap<Error>> and ? boxes whatever error a callee produced (a struct, an enum, or a plain string, which arrives as a ErrorMessage). The message is the one thing every error owes its reader; the concrete type is still there behind the box for a caller that wants to look.

ErrorContext ​

milo
pub struct ErrorContext

What r.context("reading config") wraps an error in: the note, then the cause it was raised for, so the message reads outermost first ("reading config: not found: x.toml"). The cause is any boxed Error, so a chain nests as deep as the call stack that annotated it.

Fields: note: string, cause: Heap<Error>.

ErrorContext.message ​

milo
fn ErrorContext.message(self: &ErrorContext): string

The note, a colon, and the cause's own message.

ErrorMessage ​

milo
pub struct ErrorMessage

A string error boxed as an Error: what ? makes of a Result<T, string> in a fn that returns Result<T, Heap<Error>>.

Fields: text: string.

ErrorMessage.message ​

milo
fn ErrorMessage.message(self: &ErrorMessage): string

The string the error was raised with.

Unit ​

milo
pub struct Unit

The single success value for operations that return no data. Use Result<Unit, E> for fallible commands; void is a function return type, not a value that can inhabit Result.