Skip to main content
Home
Works with
This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score100%
Published2 years ago (1.0.0)

Rust inspired types for Typescript. Includes `Result` and `Option`.

@justbe/rust-types

Rust inspired types for TypeScript.

Examples

Result type

import { Result } from "@justbe/rust-types";

// Use `Result.ok` to construct an OK type
const ok = Result.ok("this works");

// Use `Result.err` to construct an Error type
const err = Result.err(new Error("something went wrong!"));

/// Safely coerce the results of a promise into a result type
const promiseResult = await Result.fromPromise(myPromise);

// `isErr` or `isOk` can be used to check the kind of result
if (promiseResult.isErr()) {
  // handle your error...
}

// Use `unwrap` to get the value of the result. Throws if the result is an error.
const myValue = promiseResult.unwrap();

Option type

import { Option } from "@justbe/rust-types";

// Use `Option.some` to construct a `Some` type
const some = Option.some("value");

// Use `Option.none` to construct a `None` type
const none = Option.none();

// Construct an option from a type that might be `null` or `undefined`
const optionalValue = Option.from(someValue);

// `isSome` or `isNone` can be used to check the state of the value
if (optionalValue.isNone()) {
}

Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@justbe/rust-types

Import symbol

import * as rust_types from "@justbe/rust-types";
or

Import directly with a jsr specifier

import * as rust_types from "jsr:@justbe/rust-types";

Add Package

pnpm i jsr:@justbe/rust-types
or (using pnpm 10.8 or older)
pnpm dlx jsr add @justbe/rust-types

Import symbol

import * as rust_types from "@justbe/rust-types";

Add Package

yarn add jsr:@justbe/rust-types
or (using Yarn 4.8 or older)
yarn dlx jsr add @justbe/rust-types

Import symbol

import * as rust_types from "@justbe/rust-types";

Add Package

vlt install jsr:@justbe/rust-types

Import symbol

import * as rust_types from "@justbe/rust-types";

Add Package

npx jsr add @justbe/rust-types

Import symbol

import * as rust_types from "@justbe/rust-types";

Add Package

bunx jsr add @justbe/rust-types

Import symbol

import * as rust_types from "@justbe/rust-types";