0.3.1 • Published 1 year ago

@yyhhenry/rust-result v0.3.1

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

@yyhhenry/rust-result

Rust-like error handling in TypeScript.

Installation

pnpm add @yyhhenry/rust-result

Usage

import { anyhow, err, ok, safely } from "@yyhhenry/rust-result";
const safeJsonParse = (s: string) => safely(() => JSON.parse(s));
const result = safeJsonParse('{"a": 1}');
// Or
// const result = safeJsonParse('{"a": 1');
console.log(result.isOk() ? result.unwrap() : result.unwrapErr().message);
// It's safe to call unwrap() method in TypeScript,
// since it's only available when the type is narrowed to Ok.
0.3.1

1 year ago

0.3.0

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago