typerust
v0.5.2
Published
A library that provides Rust types in TypeScript.
Downloads
156
Readme
typerust
A library that provides Rust types in TypeScript. This library contains TypeScript implementations of the following Rust types: Result, Option, HashMap, and HashSet.
Installation
# deno
deno add npm:typerust
# npm
npm install --save-dev typerustUsage
Result
import { Result } from "typerust";
const success = Result.Ok(42);
const failure = Result.Err("something went wrong");
if (success.isOk()) console.log(success.unwrap());
const fromPromise = Result.from(Promise.resolve(100));Option
import { Option } from "typerust";
const some = Option.Some(10);
const none = Option.None;
if (some.isSome()) console.log(some.unwrap());
const fromNullable = Option.from(null);HashMap
import { HashMap } from "typerust";
const map = HashMap.from({ key: "value" });
const entry = map.get("key");
if (entry) console.log(entry.value);HashSet
import { HashSet } from "typerust";
const set = HashSet.from([1, 2, 3]);
const exists = set.contains(2);
if (exists) console.log("Found 2");Project layout
src/
├── hashmap/ # Rust-like HashMap.
├── hashset/ # Rust-like HashSet.
├── option/ # Option type (Some/None).
├── result/ # Result type (Ok/Err).
└── mod.ts # Main entry point.Contributing
- Fork the repository.
- Create your feature branch (
git checkout -b feature/name). - Ensure all code passes
deno task lint. - Open a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
