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.

v0.5 supports user functions returning Option<T> for bitcopy payloads (i64, f64, bool, and other non-heap-owning types). Composite returns of heap-owning payloads (e.g. Option<string>) are rejected at compile time until tag-aware drop is implemented.

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<i64> = 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<i64>) -> bool

Returns true if the option contains a value.

Function is_none_int

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

Returns true if the option is None.

Function unwrap_int

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

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

Function unwrap_or_int

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

Unwrap the i64 value, or return fallback if None.

Function map_int

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

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

Function contains_int

pub fn contains_int(opt: Option<i64>, needle: i64) -> 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 map_str

pub fn map_str(opt: Option<string>, f: fn(string) -> string) -> Option<string>

Apply f to the contained string value, or return None if empty. NOTE: This function is currently blocked by the heap-owning composite return boundary. It will become usable once tag-aware drop is implemented.

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.

Function map_f64

pub fn map_f64(opt: Option<f64>, f: fn(f64) -> f64) -> Option<f64>

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

Function contains_f64

pub fn contains_f64(opt: Option<f64>, needle: f64) -> bool

Returns true if the option contains needle.