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

std/expected

expected<T, E> represents success (T) or error (E).

import "std/expected";

fun parse_age(age: int64) -> expected<int64, string> {
    if age < 0 {
        return expected<int64, string>::unexpected("invalid age");
    }
    return expected<int64, string>::expect(age);
}

Key APIs:

  • expect
  • unexpected
  • is_expected
  • is_unexpected
  • expected_value / unexpected_value
  • expected_value_or / unexpected_value_or