Overview
Constructs anErr variant of Result. This represents a failed computation with an error value.
Signature
Parameters
The error value to wrap in an Err result. Can be any type including strings, Error objects, or custom error types.
Returns
Returns anErr<T, E> instance containing the provided error value.
Examples
Basic Usage
With Error Objects
Type Annotations
In Function Returns
Behavior
When a Result is anErr:
.isErr()returnstrue.isOk()returnsfalse- Mapping functions like
.map()are skipped - Error mapping functions like
.mapErr()are applied - The error value is accessible via
.errorproperty (after type narrowing) or._unsafeUnwrapErr()
Related
- ok() - Create an Ok variant
- Result.isOk() - Check if a Result is Ok
- Result.isErr() - Check if a Result is Err
- Result.mapErr() - Transform error values