🚀 Socket Launch Week 🚀 Day 5: Introducing Socket Fix.Learn More
Socket
Sign inDemoInstall
Socket

@ollopa/trust

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ollopa/trust

Rust idioms in Typescript

0.0.1
latest
npm
Version published
Weekly downloads
1.5K
-56%
Maintainers
1
Weekly downloads
 
Created
Source

trust

Utility library to add Rust idioms into

installing

npm install @ollopa/trust
yarn add @ollopa/trust

Add "experimentalDecorators": true, to your tsconfig.json file.

Docs

The purpose of this library is to give Typescript ergonomic Rust idioms.

Please open a RFC issue if an API can be improved in any way.

match

Very open for suggestions on a better API for this.

WIP. Needs range, default, etc.

const token: { type: 'semi' | 'identifier' | 'unknown', value: string } = getToken()

const result = match(token.type,
  // match arms
  ['semi', handleSemi(token)],
  ['identifier', handleIdentifier(token)],
  ['unknown', handleUnknown(token)],
)


match returns an Option because of limitations with typing. For example...

match('some string',
  ['yeet', 'yoot']
)

...will never match to anything and therefore will return an Option.None.

Var

Utility type to create a sum type.

type ASTNode = 
  Var<'int' | 'string' | 'infix', { token: string }> // the `token` data is common across all nodes
  & ( // Enum variants
    Var<'int', { value: number }> | 
    Var<'string', { value: string }> |
    Var<'infix', { operator: '+' | '-', left: ASTNode, right: ASTNode }> 
  )

Keywords

Rust

FAQs

Package last updated on 27 Sep 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts