{"id":16930418,"url":"https://github.com/tmccombs/randoid","last_synced_at":"2025-04-11T19:32:45.027Z","repository":{"id":65262048,"uuid":"589123707","full_name":"tmccombs/randoid","owner":"tmccombs","description":"Rust nanoid implementation","archived":false,"fork":false,"pushed_at":"2023-01-31T06:18:27.000Z","size":45,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-25T15:21:34.317Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tmccombs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-01-15T06:00:45.000Z","updated_at":"2025-03-11T12:29:14.000Z","dependencies_parsed_at":"2023-02-16T05:31:08.458Z","dependency_job_id":null,"html_url":"https://github.com/tmccombs/randoid","commit_stats":{"total_commits":28,"total_committers":1,"mean_commits":28.0,"dds":0.0,"last_synced_commit":"5b2fb0c3505611aa390baeb144a326a38e563290"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tmccombs%2Frandoid","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tmccombs%2Frandoid/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tmccombs%2Frandoid/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tmccombs%2Frandoid/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tmccombs","download_url":"https://codeload.github.com/tmccombs/randoid/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248467085,"owners_count":21108591,"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":[],"created_at":"2024-10-13T20:41:39.292Z","updated_at":"2025-04-11T19:32:44.996Z","avatar_url":"https://github.com/tmccombs.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# randoid\nRust nanoid implementation\n\nThis is a rust implementation of [`nanoid`s](https://github.com/ai/nanoid).\n\nIt generates unique IDs as strings that are more compact than UUIDs.\n\nBy default, it generates strings of 21 characters from an alphabet of 64 symbols\n(a-z, A-Z, 0-9, \"_\", and \"-\").\n\n## Features\n\nThis particular implementation of nanoid has the following features (many of which differ from the [`nanoid` crate](https://github.com/nikolay-govorov/nanoid)):\n\n- no_std support\n- can be used without allocating (by writing characters directly to output)\n- Allows using any [`Rng`](https://docs.rs/rand/latest/rand/trait.Rng.html) implementation as a source of random data.\n- Implementation is optimized for the size of the alphabet being a power of 2\n- [`smartstring`](https://crates.io/crates/smartstring) support, if the `smartstring` features is enabled (as an additive feature).\n\n## Limitations\n\n- Requires knowing the size of the alphabet at compile time (the main reason for this is it can help the compiler optimize it better)\n- Size of alphabet must be a power of 2\n- Use of generics could increase compilation time\n\nIf you want a more generalized alphabet that doesn't have a size that is a power of two and/or isn't know in advance, then\n[`rand::distributions::Slice`](https://docs.rs/rand/0.8.5/rand/distributions/struct.Slice.html) is probably sufficient. For example:\n\n```rust\nuse rand::{Rng, distributions::Slice, thread_rng};\n\nlet alphabet = ['1', '2', '3', '4', '5', '6', '7', '9', '0', 'a', 'b', 'c'];\nlet id: String = thread_rng().sample_iter(\u0026Slice::new(\u0026alphabet).unwrap()).take(21).collect();\n```\n\n## Feature Flags\n\n- `alloc`: Requires use of the `alloc` crate, and allows creating an id as a `String`\n- `std`: Use full `std` library\n- `std-rand`: Inlcude `rand/std` and `rand/std_rng` features, and add support for using `thread_rng()` as the default source of random data.\n- `smartstring`: Add a function for creating an id as a `SmartString`\n\n## Usage\n\n### Install\n\n```toml\n[dependencies]\nrandoid = \"0.3.0\"\n```\n\n### Simple\n\n```rust\nuse randoid::{randoid, Generator};\n\n// All of the below generate a string like \"9wxwPU-kQU-RDjYdxj6Eq\"\nlet id = randoid();\nlet id = randoid!();\nlet id = Generator::default().gen();\n```\n\n### Custom length\n\n```rust\n\nuse randoid::{randoid, Generator};\n\n// The below generate a string like \"M_P_lJcWfI\"\nlet id = randoid!(10);\nlet id = Generator::with_size(10).gen();\n```\n\n### Custom alphabet\n\n```rust\nuse randoid::{randoid, Generator};\n\nlet id = randoid!(21, ['a', 'b', 'c', 'd']);\nlet id = Generator::with_alphabet(\u0026randoid::alphabet::HEX).gen();\n```\n\n### Custom random number generator\n\n```rust\nuse randoid::{randoid, Generator};\nuse rand::rngs::OsRng;\n\nlet id = randoid!(21, \u0026randoid::alphabet::DEFAULT, OsRng);\nlet id = Generator::with_random(OsRng).gen();\n```\n\n## About the name\n\n\"nanoid\" was already taken by a similar library. I considered something like \"nano-id\" or \"nanoid2\",\nbut thought those were too similar. Since the IDs are generated randomly, I decided on \"randoid\" as\nan abbreviation of \"RANDOm ID\".\n\n## Acknowledgments\n\nThe original [nanoid](https://github.com/ai/nanoid) of course.\n\nAlso, \u003chttps://github.com/nikolay-govorov/nanoid\u003e, as inspiration for this project.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftmccombs%2Frandoid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftmccombs%2Frandoid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftmccombs%2Frandoid/lists"}