{"id":15677531,"url":"https://github.com/bobankh/idgenerator","last_synced_at":"2025-04-14T00:43:32.755Z","repository":{"id":57634483,"uuid":"418809627","full_name":"BobAnkh/idgenerator","owner":"BobAnkh","description":"A powerful unique id generator written in rust. Support multiple kinds of usage of worker id in one instance","archived":false,"fork":false,"pushed_at":"2024-11-07T09:18:52.000Z","size":57,"stargazers_count":17,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-27T14:55:01.218Z","etag":null,"topics":["distributed","generator","id","rust","unique"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/idgenerator","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/BobAnkh.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-10-19T07:06:58.000Z","updated_at":"2025-03-25T13:54:22.000Z","dependencies_parsed_at":"2024-06-07T15:13:49.226Z","dependency_job_id":"301b7d07-7eef-4ba8-9e53-4590176a8390","html_url":"https://github.com/BobAnkh/idgenerator","commit_stats":{"total_commits":20,"total_committers":2,"mean_commits":10.0,"dds":0.09999999999999998,"last_synced_commit":"aee4aa11a57d68dbaf6ec9a110c20139f8dc5982"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BobAnkh%2Fidgenerator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BobAnkh%2Fidgenerator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BobAnkh%2Fidgenerator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BobAnkh%2Fidgenerator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BobAnkh","download_url":"https://codeload.github.com/BobAnkh/idgenerator/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248804721,"owners_count":21164127,"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":["distributed","generator","id","rust","unique"],"created_at":"2024-10-03T16:09:50.042Z","updated_at":"2025-04-14T00:43:32.730Z","avatar_url":"https://github.com/BobAnkh.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"﻿# IdGenerator\n\n[![github-repo](https://img.shields.io/badge/github-BobAnkh/idgenerator-f5dc23?logo=github)](https://github.com/BobAnkh/idgenerator)\n[![LICENSE Apache-2.0](https://img.shields.io/github/license/BobAnkh/idgenerator?logo=Apache\u0026color=green)](https://github.com/BobAnkh/idgenerator/blob/main/LICENSE)\n\n[![docs.rs](https://img.shields.io/badge/docs.rs-idgenerator-blue?logo=data:image/svg+xml;base64,PHN2ZyByb2xlPSJpbWciIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgdmlld0JveD0iMCAwIDUxMiA1MTIiPjxwYXRoIGZpbGw9IiNmNWY1ZjUiIGQ9Ik00ODguNiAyNTAuMkwzOTIgMjE0VjEwNS41YzAtMTUtOS4zLTI4LjQtMjMuNC0zMy43bC0xMDAtMzcuNWMtOC4xLTMuMS0xNy4xLTMuMS0yNS4zIDBsLTEwMCAzNy41Yy0xNC4xIDUuMy0yMy40IDE4LjctMjMuNCAzMy43VjIxNGwtOTYuNiAzNi4yQzkuMyAyNTUuNSAwIDI2OC45IDAgMjgzLjlWMzk0YzAgMTMuNiA3LjcgMjYuMSAxOS45IDMyLjJsMTAwIDUwYzEwLjEgNS4xIDIyLjEgNS4xIDMyLjIgMGwxMDMuOS01MiAxMDMuOSA1MmMxMC4xIDUuMSAyMi4xIDUuMSAzMi4yIDBsMTAwLTUwYzEyLjItNi4xIDE5LjktMTguNiAxOS45LTMyLjJWMjgzLjljMC0xNS05LjMtMjguNC0yMy40LTMzLjd6TTM1OCAyMTQuOGwtODUgMzEuOXYtNjguMmw4NS0zN3Y3My4zek0xNTQgMTA0LjFsMTAyLTM4LjIgMTAyIDM4LjJ2LjZsLTEwMiA0MS40LTEwMi00MS40di0uNnptODQgMjkxLjFsLTg1IDQyLjV2LTc5LjFsODUtMzguOHY3NS40em0wLTExMmwtMTAyIDQxLjQtMTAyLTQxLjR2LS42bDEwMi0zOC4yIDEwMiAzOC4ydi42em0yNDAgMTEybC04NSA0Mi41di03OS4xbDg1LTM4Ljh2NzUuNHptMC0xMTJsLTEwMiA0MS40LTEwMi00MS40di0uNmwxMDItMzguMiAxMDIgMzguMnYuNnoiPjwvcGF0aD48L3N2Zz4K)](https://docs.rs/idgenerator)\n[![crates.io](https://img.shields.io/crates/v/idgenerator.svg?logo=rust\u0026color=orange)](https://crates.io/crates/idgenerator)\n[![codecov](https://codecov.io/gh/BobAnkh/idgenerator/branch/main/graph/badge.svg?token=XD4EOZI5ZH)](https://codecov.io/gh/BobAnkh/idgenerator)\n\nA powerful unique id generator.\n\n**ATTENTION**: Now this crate has upgraded to **v2**, meaning most of the interfaces in **v1** is deprecated. If you still want to use **v1**, please see branch `v1`. You can also see [deprecated.md](deprecated.md) for how to use **v1**.\n\nShorter ID and faster generation with a new snowflake drift algorithm. The core is to shorten the ID length, but also can have a very high instantaneous concurrent processing capacity (about 50W/0.1s), and powerful configuration capacity.\n\nIf you want to have such a high throughput, please set a higher `seq_bit_len` (e.g. 10 or 12).\n\n## Usage\n\n### Out-of-the-box Instances implemented by this lib\n\nThis lib has implemented two out-of-the-box instances:\n\n- `IdInstance`: a instance with only one generator. See [examples/single.rs](examples/single.rs) for usage example.\n- `IdVecInstance`: a instance with multiple generators. See [examples/multiple.rs](examples/multiple.rs) for usage example.\n\nYou can also see how lib test works in [src/lib.rs](src/lib.rs) or how benchmark works in [bench/id_bench.rs](bench/id_bench.rs).\n\nThe steps mainly can be described as:\n\n1. Setup the options(i.e. configure the instance).\n2. Initialize the instance or set its options.\n3. Call the `next_id` method to generate unique id.\n\nWhat you can configure about the instances is demonstrated as the struct `IdGeneratorOptions`:\n\n- `method`: 1 means snowflake with shift.\n- `base_time`: base time of the snowflake algorithm, in milliseconds, can not exceed the current system time.\n- `worker_id`: should be decided externally, smaller than `2^worker_id_bit_len-1`.\n- `worker_id_bit_len`: the bit length of worker_id, default to 8, in range \\[1, 15\\]. **`worker_id_bit_len + seq_bit_len` should be less than 22**.\n- `seq_bit_len`: the bit length of sequence, default to 8, in range \\[3, 21\\].\n- `max_seq_num`: set the range of \\[min_seq_num, 2^seq_bit_len-1\\], default to 0 meaning `2^seq_bit_len-1`.\n- `min_seq_num`: default to 5, range \\[5, max_seq_num\\], reserved for manually value and time turned back.\n- `top_over_cost_count`: max shift count(included), default to 2000, recommended range is [500, 20000] (associated with computing ability).\n\nA very simple example:\n\n```rust\nuse idgenerator::*;\n\nfn main() {\n    // Setup the option for the id generator instance.\n    let options = IdGeneratorOptions::new().worker_id(1).worker_id_bit_len(6);\n    // Initialize the id generator instance with the option.\n    // Other options not set will be given the default value.\n    let _ = IdInstance::init(options)?;\n    // Call `next_id` to generate a new unique id.\n    let id = IdInstance::next_id();\n    println!(\"id is {}\", id);\n}\n```\n\nFor more complex usage, see directory `examples`.\n\n### Self-implement Instances\n\nThis lib wraps the snowflake algorithm inside the `CoreIdGenerator` struct. You can wrap this struct inside your own instance of unique id generator.\n\nFor more details, please refer to [Documentation](https://docs.rs/idgenerator).\n\n## Credits\n\n- Inspired by [yitter/IdGenerator](https://github.com/yitter/IdGenerator)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbobankh%2Fidgenerator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbobankh%2Fidgenerator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbobankh%2Fidgenerator/lists"}