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

Creating enum values

Payload arguments move into the enum. Constructing it adds no allocation:

enum Message:
    Empty
    Text(str)

def main() -> Result[(), IoError]:
    print(Message.Text("hello"))?
    print(Message.Empty)?
    Ok(())
Message.Text("hello")
Message.Empty

Allocations inside argument expressions, such as building a string, still return their own Result.