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

Bluzzi/rustic-error

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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