Skip to content

Latest commit

 

History

History
46 lines (30 loc) · 1.18 KB

Err.md

File metadata and controls

46 lines (30 loc) · 1.18 KB

happy-rustyDocs


happy-rusty / Err

Function: 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 Parameters

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.

Parameters

Parameter Type Description
error E The error to wrap as an Err result.

Returns

Result<T, E>

A Result<T, E> that contains the provided error, representing the Err case.

Example

const badResult = Err<number, Error>(new Error('Something went wrong'));
if (badResult.isErr()) {
  console.error(badResult.unwrapErr()); // Outputs: Error: Something went wrong
}

Defined in

prelude.ts:473