NAME
std/result - A simple Result object for explicit success and failure values.
SYNOPSIS
from std/result import Result;
let r := Result.ok(42);
if ( r.is_ok() ) {
say r.unwrap();
}
IMPLEMENTATION SUPPORT
This module is supported by all implementations of ZuzuScript.
DESCRIPTION
Result is a small, subclassable object modelled on a simplified version of Rust's Result concept. It is useful when a function, task, or worker wants to return an explicit success or failure value without throwing an exception.
It is a normal ZuzuScript class. Workers do not require Result; any value supported by std/marshal may be returned.
EXPORTS
Classes
ResultContainer for either an ok value or an error value.
Result.ok(value)Parameters:
valueis any success value. Returns:Result. Creates an ok result wrappingvalue.Result.err(error)Parameters:
erroris any error value. Returns:Result. Creates an error result wrappingerror.result.is_ok()Parameters: none. Returns:
Boolean. Returns true when the result is an ok value.result.is_err()Parameters: none. Returns:
Boolean. Returns true when the result is an error value.result.value()Parameters: none. Returns: value. Returns the stored ok value, or
nullfor an error result.result.error()Parameters: none. Returns: value. Returns the stored error value, or
nullfor an ok result.result.unwrap()Parameters: none. Returns: value. Returns the ok value, or throws if the result is an error.
result.unwrap_err()Parameters: none. Returns: value. Returns the error value, or throws if the result is ok.
COPYRIGHT AND LICENCE
std/result is copyright Toby Inkster.
It is free software; you may redistribute it and/or modify it under the terms of either the Artistic License 1.0 or the GNU General Public License version 2.