Skip to content

Err Reference

Err is a class that represents an error or failure value. It is one of the two possible states of a Result.

Creates a Result representing an error.

var result = Err("File not found");
  • error: dyn? optional - The error value to wrap

Returns athe message of the error.

var err_result = Err("Error message.");
println(err_result.to_string());

None

String - The error message as a string.

All other methods are inherited from the Result class. See the Result reference for documentation.

var failure = Err("Something went wrong");
println(failure.is_err()); // true
println(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