rustic-error
TypeScript icon, indicating that this package has built-in type declarations

0.2.3 • Public • Published

Rustic Error

Robust and type-safe error management inspired by Rust's Result pattern.

Example

import type { Result } from "rustic-error";
import { ok, error } from "rustic-error"; 

function divide(a: number, b: number): Result<number, string> {
  if (b === 0) return error("Division by zero");

  return ok(a / b);
}

const foo = divide(1 / 2);

if (foo.ok) {
  console.log("Result", foo.value);
} else {
  console.log("Error", foo.error);
}

Readme

Keywords

Package Sidebar

Install

npm i rustic-error

Weekly Downloads

2

Version

0.2.3

License

MIT

Unpacked Size

12.3 kB

Total Files

28

Last publish

Collaborators

  • bluzzi