Skip to main content

Built and signed on GitHub Actions

Porting some excellent design implementations from Rust to JavaScript.

This package works with Bun, Node.js, Deno, BrowsersIt is unknown whether this package works with Cloudflare Workers
JSR Score
100%
Published
5 days ago (1.1.0)
function Err

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.

Examples

Example 1

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

Type Parameters

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

error: E
  • The error to wrap as an Err result.

Return Type

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

Add Package

deno add @happy-js/happy-rusty

Import symbol

import { Err } from "@happy-js/happy-rusty";

Add Package

npx jsr add @happy-js/happy-rusty

Import symbol

import { Err } from "@happy-js/happy-rusty";

Add Package

yarn dlx jsr add @happy-js/happy-rusty

Import symbol

import { Err } from "@happy-js/happy-rusty";

Add Package

pnpm dlx jsr add @happy-js/happy-rusty

Import symbol

import { Err } from "@happy-js/happy-rusty";

Add Package

bunx jsr add @happy-js/happy-rusty

Import symbol

import { Err } from "@happy-js/happy-rusty";