Skip to main content

@happy-js/happy-rusty@1.0.9

Porting some excellent design implementations from Rust to JavaScript.

Works with
This package works with Bun
It is unknown whether this package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Browsers
JSR Score
100%
Published
6 days ago

Use Rust features in JavaScript happily

NPM version JSR Version JSR Score Build Status


[中文]


Partial supported

More is coming

Installation

via pnpm

pnpm add happy-rusty

or via yarn

yarn add happy-rusty

or just from npm

npm install --save happy-rusty

via JSR

jsr add @happy-js/happy-rusty

for deno

deno add @happy-js/happy-rusty

for bun

bunx jsr add @happy-js/happy-rusty

then import to your code.

import { Some, None, Ok, Err } from 'happy-rusty';

Enjoy the happiness.

Examples

import { Some, None, Ok, Err } from 'happy-rusty';

function judge(n: number): Option<Promise<Result<number, Error>>> {
    if (n < 0 || n >= 1) {
        return None;
    }

    return Some(new Promise(resolve => {
        const r = Math.random();
        resolve(r > n ? Ok(r) : Err(new Error('lose')));
    }));
}

const res = judge(0.8);
if (res.isNone()) {
    console.error('invalid number');
} else {
    const result = await res.unwrap();
    if (result.isErr()) {
        console.assert(result.err().message === 'lose');
    } else {
        console.log(result.unwrap()); // must greater than 0.8
    }
}
Built and signed on
GitHub Actions
View transparency log

Add Package

deno add @happy-js/happy-rusty

Import symbol

import * as mod from "@happy-js/happy-rusty";

Add Package

npx jsr add @happy-js/happy-rusty

Import symbol

import * as mod from "@happy-js/happy-rusty";

Add Package

yarn dlx jsr add @happy-js/happy-rusty

Import symbol

import * as mod from "@happy-js/happy-rusty";

Add Package

pnpm dlx jsr add @happy-js/happy-rusty

Import symbol

import * as mod from "@happy-js/happy-rusty";

Add Package

bunx jsr add @happy-js/happy-rusty

Import symbol

import * as mod from "@happy-js/happy-rusty";