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.

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

Examples

import std::result;

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

    let y: Result<i64, i64> = 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<i64, i64>) -> bool

Returns true if the result contains an Ok value.

Function is_err_int

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

Returns true if the result contains an Err value.

Function unwrap_int

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

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

Function unwrap_err_int

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

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

Function unwrap_or_int

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

Unwrap the Ok value, or return fallback if Err.

Function map_int

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

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

Function map_err_int

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

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

Function contains_int

pub fn contains_int(r: Result<i64, i64>, needle: i64) -> 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.