std::optionOption 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.
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
}
is_some_intReturns true if the option contains a value.
is_none_intReturns true if the option is None.
unwrap_intUnwrap the i64 value. Panics if the option is None.
unwrap_or_intUnwrap the i64 value, or return fallback if None.
map_intApply f to the contained i64 value, or return None if empty.
contains_intReturns true if the option contains needle.
is_some_strReturns true if the option contains a value.
is_none_strReturns true if the option is None.
unwrap_strUnwrap the string value. Panics if the option is None.
unwrap_or_strUnwrap the string value, or return fallback if None.
map_strApply 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.
contains_strReturns true if the option contains needle.
is_some_f64Returns true if the option contains a value.
is_none_f64Returns true if the option is None.
unwrap_f64Unwrap the f64 value. Panics if the option is None.
unwrap_or_f64Unwrap the f64 value, or return fallback if None.
map_f64Apply f to the contained f64 value, or return None if empty.
contains_f64Returns true if the option contains needle.