@justbe/rust-types@1.0.0
latest
zephraph/rust-typesWorks with
•JSR Score100%•This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers




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()) { }
Add Package
deno add jsr:@justbe/rust-types
Import symbol
import * as rust_types from "@justbe/rust-types";
Import directly with a jsr specifier
import * as rust_types from "jsr:@justbe/rust-types";
Add Package
pnpm i jsr:@justbe/rust-types
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
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";