{"id":22871253,"url":"https://github.com/0x7030676e31/rustty","last_synced_at":"2025-05-05T22:17:57.730Z","repository":{"id":152919803,"uuid":"627571935","full_name":"0x7030676e31/rustty","owner":"0x7030676e31","description":"A package that brings the iconic Rust types such as Result and more","archived":false,"fork":false,"pushed_at":"2023-11-17T20:26:32.000Z","size":47,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-17T20:26:30.689Z","etag":null,"topics":["option","result","rust","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/0x7030676e31.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-04-13T18:40:42.000Z","updated_at":"2024-10-07T10:45:52.000Z","dependencies_parsed_at":null,"dependency_job_id":"1f9cf047-f6ec-4202-a484-ac1d570612ba","html_url":"https://github.com/0x7030676e31/rustty","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0x7030676e31%2Frustty","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0x7030676e31%2Frustty/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0x7030676e31%2Frustty/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0x7030676e31%2Frustty/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/0x7030676e31","download_url":"https://codeload.github.com/0x7030676e31/rustty/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252584336,"owners_count":21771945,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["option","result","rust","typescript"],"created_at":"2024-12-13T13:17:43.539Z","updated_at":"2025-05-05T22:17:57.701Z","avatar_url":"https://github.com/0x7030676e31.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Rustty\n\n**Rustty** is a library that brings various data structures and algorithms such as iconic **Result** and **Option** from the Rust standard library to the JavaScript world.\n\n---\n\nIf you like this project, please consider leaving a star on the [GitHub repository](https://github.com/0x7030676e31/rustty) ✨\n\n## Installation\n\n```bash\nnpm install rustty\n```\n\n## Usage\n\nYou can either import the whole library or just the **Result** and **Option** types.\n\n```js\nimport \"rustty\";\n```\nWill import only the **Result** and **Option** types.\nOn the other hand, if you want to import the whole library, you can do by using the following statement:\n\n```js\nimport \"rustty/full\";\n```\nNote that using the full version will add a lot of methods to the prototypes of the built-in types such as **Array**.\n\n## Examples\n### Using Result and Option \n\n```ts\nimport \"rustty\";\n\nfunction divide(a: number, b: number): Result\u003cnumber, string\u003e {\n  if (b === 0) {\n    return Err(\"Division by zero\");\n  }\n\n  return Ok(a / b);\n}\n\nconst result = divide(10, 5); // Ok(2)\n\nconsole.assert(result.isOk() === true); \nconsole.assert(result.unwrap() === 2);\n\nconst failed = divide(10, 0); // Err(\"Division by zero\")\n\nconsole.assert(failed.isErr() === true);\nconsole.assert(failed.unwrapErr() === \"Division by zero\");\n\n// Alternatively, you can use Option type to indicate that the result may be null or undefined\n\nfunction divide(a: number, b: number): Option\u003cnumber\u003e {\n  if (b === 0) {\n    return None;\n  }\n\n  return Some(a / b);\n}\n\nconst result = divide(10, 5).unwrap(); // 2\nconst failed = divide(10, 0).unwrap(); // Throws an error\n```\n\n### Using additional methods\n\n```ts\nimport \"rustty/full\";\n\nconst arr = [1, 2, 3, 4, 5];\n\n// Swap elements at indices 0 and 4\narr.swap(0, 4);\n\narr.windows(2).forEach(window =\u003e {\n  console.log(window); // [5, 2], [2, 3], [3, 4], [4, 1]\n});\n\nconsole.assert(arr.sum() === 15);\nconsole.assert(arr.product() === 120);\n\narr.swap(0, 4);\n\narr\n  .groupBy((a, b) =\u003e Math.round(a / 2) === Math.round(b / 2))\n  .forEach(group =\u003e console.log(group)); // [1, 2], [3, 4], [5]\n\nconsole.assert(arr.max() === 5);\nconsole.assert(arr.min() === 1);\n```\n\n## Features\nNote that every name has been changed to camelCase to be consistent with the JavaScript naming convention.\n\n- [✅] Result with most of its methods (Global scope)\n- [✅] Option with most of its methods (Global scope)\n- [✅] Most of the methods from Vec (Array) (drain_filter -\u003e spliceFilter)\n- [✅] Most of the methods from Slice (Array)\n- [✅] Most of the methods from Iterator (Array)\n- [❌] Most of the methods from String\n- [❌] Most of the methods from HashMap\n- [❌] Most of the methods from HashSet\n- [❌] Most of the methods from Numbers\n\nIf you can't find a method that you need, feel free to open an issue or a pull request.\n\n## License\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F0x7030676e31%2Frustty","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F0x7030676e31%2Frustty","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F0x7030676e31%2Frustty/lists"}