Skip to main content

Overview

Constructs an Err variant of Result. This represents a failed computation with an error value.

Signature

Parameters

E
required
The error value to wrap in an Err result. Can be any type including strings, Error objects, or custom error types.

Returns

Returns an Err<T, E> instance containing the provided error value.

Examples

Basic Usage

With Error Objects

Type Annotations

In Function Returns

Behavior

When a Result is an Err:
  • .isErr() returns true
  • .isOk() returns false
  • Mapping functions like .map() are skipped
  • Error mapping functions like .mapErr() are applied
  • The error value is accessible via .error property (after type narrowing) or ._unsafeUnwrapErr()