Module std::option

Option helper functions โ€” pure Hew alternatives to the Rust FFI runtime.

These functions provide idiomatic Hew wrappers for common Option<T> operations. They use match on the built-in Option type and avoid FFI calls entirely for the supported element types.

Examples

import std::option;

fn main() {
    let x = Some(42);
    println(option.is_some_int(x));        // true
    println(option.unwrap_or_int(x, 0));   // 42

    let y: Option<int> = None;
    println(option.is_none_int(y));         // true
    println(option.unwrap_or_int(y, -1));   // -1
}

Contents

Functions

Function is_some_int

pub fn is_some_int(opt: Option<int>) -> bool

Returns true if the option contains a value.

Function is_none_int

pub fn is_none_int(opt: Option<int>) -> bool

Returns true if the option is None.

Function unwrap_int

pub fn unwrap_int(opt: Option<int>) -> int

Unwrap the int value. Panics if the option is None.

Function unwrap_or_int

pub fn unwrap_or_int(opt: Option<int>, fallback: int) -> int

Unwrap the int value, or return fallback if None.

Function map_int

pub fn map_int(opt: Option<int>, f: fn(int) -> int) -> Option<int>

Apply f to the contained int value, or return None if empty.

Function contains_int

pub fn contains_int(opt: Option<int>, needle: int) -> bool

Returns true if the option contains needle.

Function is_some_str

pub fn is_some_str(opt: Option<String>) -> bool

Returns true if the option contains a value.

Function is_none_str

pub fn is_none_str(opt: Option<String>) -> bool

Returns true if the option is None.

Function unwrap_str

pub fn unwrap_str(opt: Option<String>) -> String

Unwrap the String value. Panics if the option is None.

Function unwrap_or_str

pub fn unwrap_or_str(opt: Option<String>, fallback: String) -> String

Unwrap the String value, or return fallback if None.

Function contains_str

pub fn contains_str(opt: Option<String>, needle: String) -> bool

Returns true if the option contains needle.

Function is_some_f64

pub fn is_some_f64(opt: Option<f64>) -> bool

Returns true if the option contains a value.

Function is_none_f64

pub fn is_none_f64(opt: Option<f64>) -> bool

Returns true if the option is None.

Function unwrap_f64

pub fn unwrap_f64(opt: Option<f64>) -> f64

Unwrap the f64 value. Panics if the option is None.

Function unwrap_or_f64

pub fn unwrap_or_f64(opt: Option<f64>, fallback: f64) -> f64

Unwrap the f64 value, or return fallback if None.