Module std::result

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

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

Examples

import std::result;

fn main() {
    let x: Result<int, int> = Ok(42);
    println(result.is_ok_int(x));          // true
    println(result.unwrap_or_int(x, 0));   // 42

    let y: Result<int, int> = Err(1);
    println(result.is_err_int(y));          // true
    println(result.unwrap_or_int(y, -1));   // -1
}

Contents

Functions

Function is_ok_int

pub fn is_ok_int(r: Result<int, int>) -> bool

Returns true if the result contains an Ok value.

Function is_err_int

pub fn is_err_int(r: Result<int, int>) -> bool

Returns true if the result contains an Err value.

Function unwrap_int

pub fn unwrap_int(r: Result<int, int>) -> int

Unwrap the Ok value. Panics if the result is Err.

Function unwrap_err_int

pub fn unwrap_err_int(r: Result<int, int>) -> int

Unwrap the Err value. Panics if the result is Ok.

Function unwrap_or_int

pub fn unwrap_or_int(r: Result<int, int>, fallback: int) -> int

Unwrap the Ok value, or return fallback if Err.

Function map_int

pub fn map_int(r: Result<int, int>, f: fn(int) -> int) -> Result<int, int>

Apply f to the contained Ok value, or return Err unchanged.

Function map_err_int

pub fn map_err_int(r: Result<int, int>, f: fn(int) -> int) -> Result<int, int>

Apply f to the contained Err value, or return Ok unchanged.

Function contains_int

pub fn contains_int(r: Result<int, int>, needle: int) -> bool

Returns true if the result is Ok and contains needle.

Function is_ok_str

pub fn is_ok_str(r: Result<String, String>) -> bool

Returns true if the result contains an Ok value.

Function is_err_str

pub fn is_err_str(r: Result<String, String>) -> bool

Returns true if the result contains an Err value.

Function unwrap_str

pub fn unwrap_str(r: Result<String, String>) -> String

Unwrap the Ok value. Panics if the result is Err.

Function unwrap_err_str

pub fn unwrap_err_str(r: Result<String, String>) -> String

Unwrap the Err value. Panics if the result is Ok.

Function unwrap_or_str

pub fn unwrap_or_str(r: Result<String, String>, fallback: String) -> String

Unwrap the Ok value, or return fallback if Err.

Function contains_str

pub fn contains_str(r: Result<String, String>, needle: String) -> bool

Returns true if the result is Ok and contains needle.

Function is_ok_f64

pub fn is_ok_f64(r: Result<f64, String>) -> bool

Returns true if the result contains an Ok value.

Function is_err_f64

pub fn is_err_f64(r: Result<f64, String>) -> bool

Returns true if the result contains an Err value.

Function unwrap_f64

pub fn unwrap_f64(r: Result<f64, String>) -> f64

Unwrap the Ok value. Panics if the result is Err.

Function unwrap_or_f64

pub fn unwrap_or_f64(r: Result<f64, String>, fallback: f64) -> f64

Unwrap the Ok value, or return fallback if Err.