Skip to content
This repository has been archived by the owner on Jun 13, 2024. It is now read-only.

Latest commit

 

History

History
22 lines (17 loc) · 458 Bytes

README.md

File metadata and controls

22 lines (17 loc) · 458 Bytes

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);
}