Skip to content
ghaerdi edited this page Aug 14, 2026 · 3 revisions

rustify Wiki

A TypeScript library inspired by Rust, providing Result and Option types for safe error handling and null management with functional programming patterns.

npm version JSR version License: MIT

Why rustify?

JavaScript/TypeScript error handling often relies on try...catch blocks or nullable return types, which can be verbose or hide potential errors. rustify brings Rust-inspired monads like Result and Option to TypeScript, enabling functional programming patterns for safer code. This allows you to:

  • Handle errors explicitly: Functions return a Result which is either Ok(value) for success or Err(error) for failure.
  • Manage nullable values safely: Use Option to represent values that may or may not exist, eliminating null/undefined errors.
  • Improve type safety: Both Result<T, E> and Option<T> types are tracked by the type system.
  • Chain operations safely: Monadic methods like andThen, map, and orElse allow elegant functional composition.
  • Perform exhaustive checks: The match method ensures you handle all cases explicitly.
  • Easily wrap unsafe functions: Result.from and Option.fromNullable provide simple ways to convert potentially unsafe operations.
  • Destructure results easily: Use asTuple() for Go-style [err, val] destructuring, or asObject() if you prefer { error, value } destructuring.

Quick Start

npm install @ghaerdi/rustify
# or
deno add @ghaerdi/rustify
import { Err, None, Ok, Option, Result, Some } from "@ghaerdi/rustify";

function divide(numerator: number, denominator: number): Result<number, string> {
  if (denominator === 0) return Err("Cannot divide by zero");
  return Ok(numerator / denominator);
}

const result = divide(10, 2);
console.log(result.unwrap()); // 5

Documentation

  • Installation — how to install with npm, yarn, pnpm, or JSR.
  • Option — full API reference for the Option<T> monad.
  • Result — full API reference for the Result<T, E> monad.
  • match — type-safe pattern matching with match().
  • Examples — worked examples for common patterns.

License

MIT License — see the LICENSE file in the repository for details.

Clone this wiki locally