Err Reference
Err is a class that represents an error or failure value. It is one of the two possible states of a Result.
Constructor
Section titled “Constructor”Creates a Result representing an error.
var result = Err("File not found");Parameters
Section titled “Parameters”- error:
dyn?optional - The error value to wrap
Methods
Section titled “Methods”to_string
Section titled “to_string”Returns athe message of the error.
var err_result = Err("Error message.");println(err_result.to_string());Parameters
Section titled “Parameters”None
Returns
Section titled “Returns”String - The error message as a string.
Inherited
Section titled “Inherited”All other methods are inherited from the Result class. See the Result reference for documentation.
Example
Section titled “Example”var failure = Err("Something went wrong");
println(failure.is_err()); // trueprintln(failure.err()); // "Something went wrong"println(failure.unwrap_or(0)); // 0
var mapped = failure.map((x) -> x * 2);println(mapped.is_err()); // true (error is unchanged)
var recovered = failure.or_else(() -> Ok(42));println(recovered.unwrap()); // 42