npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

ts-rust

v0.2.0

Published

Typescript porting of Rust's Option/Result

Downloads

33

Readme

ts-rust

Typescript porting of Rust's Option and Result

Project Goal

  • Portaing all TypeScript implementable functions from Rust's Option and Result
  • Not snake_case but camelCase
  • Debug friendly
  • No external dependency

Pre-requirements

  • TypeScript target is ES6 or above
{
  "compilerOptions": {
    "target": "es6"
  }
}

Install

$ npm install --save ts-rust

Usage

import

import {RustOption as Option, RustResult as Result} from 'ts-rust'

types

const something:Option<number> = Option.Some(123);
const nothing:Option<number> = Option.None;

const okay:Result<number, string> = Result.Ok(222);
const error:Result<number, string> = Result.Err('failed');

Examples

import {RustOption as Option, RustResult as Result} from 'ts-rust'

let latestTemperature:Option<number> = Option.None;
const temperatureHistory:number[] = [];

function setTemperature(value:number){
    latestTemperature = Option.Some(value);
    temperatureHistory.push(value);
}

function printLatestTemperature(){
    latestTemperature.match({
        Some: (v)=>console.log('latest temperature = '+ v),
        None: ()=>console.log('no data in history')
    });
}

function findMinusValues(){
    const minusTemperatures = temperatureHistory.filter(v=>v<0);
    if(minusTemperatures.length === 0){
        return Result.Err('no minus value in history')
    }
    else{
        return Result.Ok(minusTemperatures);
    }
}

setTemperature(12);
setTemperature(-3);
setTemperature(5);

printLatestTemperature(); //value=567

const result = findMinusValues();
result.map(v=>console.log('Too cold! temperature = ' + v)); //Too cold! temperature = -3

Option

$ npm run example-option

example/option.ts

const something = Option.Some(123);
const nothing = Option.None;


console.log('Some.unwrap() = ', something.unwrap()); //123

console.log('Some.unwrapOr() = ', something.unwrapOr(456)); //123
console.log('None.unwrapOr() = ', nothing.unwrapOr(456)); //456

console.log('Some.isSome() = ', something.isSome()); //true
console.log('Some.isNone() = ', something.isNone()); //false

...

Result

$ npm run example-result

example/result.ts

const okay = Result.Ok(123);
const error = Result.Err('failed');


console.log('Ok.unwrap() = ', okay.unwrap()); //123

console.log('Ok.unwrapOr() = ', okay.unwrapOr(456)); //123
console.log('Err.unwrapOr() = ', error.unwrapOr(456)); //456

console.log('Ok.isOk() = ', okay.isOk()); //true
console.log('Ok.isErr() = ', okay.isErr()); //false

Test & Coverage

$ npm run test

unported functions

Option

  • as_deref
  • as_deref_mut
  • as_mut
  • as_pin_mut
  • as_pin_ref
  • as_ref
  • copied
  • iter_mut
  • unwrap_or_default

Result

  • as_ref
  • as_mut
  • iter_mut
  • copied
  • unwrap_or_default
  • as_deref_ok
  • as_deref_err
  • as_deref
  • as_deref_mut_ok
  • as_deref_mut_err
  • as_deref_mut