0.0.0 • Published 1 year ago

rs-enums v0.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

➕ Installation

# yarn
yarn add rs-enums

# npm
npm install rs-enums

# pnpm
pnpm install rs-enums

✨ Usage

Opt<T>

std::option::Option<T>

import { Opt, Some, None } from 'rs-enums'

// generate Opt<T> with Some<T> and None<T>
const some = Some('hi')
const none = None<string>()

// Opt<T>#unwrap(): T
console.log(some.unwrap()) // 'hi'
none.unwrap() // throws an error because cannot unwrap None

Result<T, E>

std::result::Result<T, E>

import { Result, Ok, Err } from 'rs-enums'

// generates Result<T, E> with Ok<T, E> and Err<T, E>
const ok = Ok<string, string>('success')
const err = Err<string, string>('error')

console.log(ok.expect('should be ok')) // 'success'
err.expect('should be ok') // throws an error with message 'should be ok'
0.0.0

1 year ago