happy-rusty • Docs
happy-rusty / Err
function Err<T, E>(error): Result<T, E>
Creates a Result<T, E>
representing a failed outcome containing an error.
This function is used to construct a Result
that signifies the operation failed by containing the error E
.
Type Parameter | Description |
---|---|
T |
The type of the value that the result could potentially contain (not used in this case). |
E |
The type of the error to be wrapped in the Err result. |
Parameter | Type | Description |
---|---|---|
error |
E |
The error to wrap as an Err result. |
Result
<T
, E
>
A Result<T, E>
that contains the provided error, representing the Err
case.
const badResult = Err<number, Error>(new Error('Something went wrong'));
if (badResult.isErr()) {
console.error(badResult.unwrapErr()); // Outputs: Error: Something went wrong
}