{"id":18258619,"url":"https://github.com/whizzes/pxid","last_synced_at":"2025-04-04T19:31:48.323Z","repository":{"id":73674499,"uuid":"600803717","full_name":"whizzes/pxid","owner":"whizzes","description":"An extended version of XID (Globally Unique Identifiers) which supports prefixes and is stored in 16 bytes","archived":false,"fork":false,"pushed_at":"2024-11-11T07:54:35.000Z","size":121,"stargazers_count":4,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-27T07:44:49.542Z","etag":null,"topics":["graphql","id","pxid","uid","xid"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/pxid","language":"Rust","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/whizzes.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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-02-12T16:45:16.000Z","updated_at":"2024-12-31T04:13:27.000Z","dependencies_parsed_at":"2023-07-13T19:46:36.043Z","dependency_job_id":"25661b86-90fc-4d86-bf59-26a4cd8a5fd2","html_url":"https://github.com/whizzes/pxid","commit_stats":null,"previous_names":["estebanborai/pxid"],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whizzes%2Fpxid","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whizzes%2Fpxid/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whizzes%2Fpxid/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whizzes%2Fpxid/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/whizzes","download_url":"https://codeload.github.com/whizzes/pxid/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247237679,"owners_count":20906329,"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":["graphql","id","pxid","uid","xid"],"created_at":"2024-11-05T10:33:16.710Z","updated_at":"2025-04-04T19:31:43.314Z","avatar_url":"https://github.com/whizzes.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv\u003e\n  \u003ch1 align=\"center\"\u003epxid\u003c/h1\u003e\n  \u003ch4 align=\"center\"\u003e\n   Prefixed Globally Unique Identifier\n  \u003c/h4\u003e\n\u003c/div\u003e\n\n\u003cdiv align=\"center\"\u003e\n\n  [![Crates.io](https://img.shields.io/crates/v/pxid.svg)](https://crates.io/crates/pxid)\n  [![Documentation](https://docs.rs/pxid/badge.svg)](https://docs.rs/pxid)\n  ![Build](https://github.com/EstebanBorai/pxid/workflows/build/badge.svg)\n  ![Clippy](https://github.com/EstebanBorai/pxid/workflows/clippy/badge.svg)\n  ![Formatter](https://github.com/EstebanBorai/pxid/workflows/fmt/badge.svg)\n\n\u003c/div\u003e\n\n## Motivation\n\nExtend the [rs/xid][1] implementation by adding capability to have\na prefix and at the same time have a `u16` type support by fitting prefix bits.\n\nThis library is inspired in Stripe IDs which have a friendly notation and are\nvery short IDs. These IDs are prefixed with a maximum of 4 bytes belonging to\nthe entity behind them.\n\n## Usage\n\n```rust\nuse pxid::Pxid;\n\nfn main() -\u003e Result\u003c(), Box\u003cdyn std::error::Error\u003e\u003e {\n    // Given that some of the dependencies to build\n    // an instance of the Pxid may fail.\n    // - Getting current timestamp\n    // - Getting machine id\n    // - Getting process id\n    //\n    // A `Result\u003cPxid, Error\u003e` is returned.\n    let id = Pxid::new(\"acct\".as_bytes())?;\n\n    println!(\"{}\", id); // acct_9m4e2mr0ui3e8a215n4g\n}\n```\n\nTo improve memory usage (reduce allocations), and reuse dependencies required,\nthe `Factory` struct can also be used to build `Pxid` instances.\n\nThis is the recommended way to build `Pxid` instances, given that resources are\ninitialized once, and then reused.\n\n```rust\nuse pxid::Factory;\n\nfn main() -\u003e Result\u003c(), Box\u003cdyn std::error::Error\u003e\u003e {\n    let factory = Factory::new_without_prefix()?;\n    let id = factory.with_prefix(\"acct\");\n\n    println!(\"{}\", id); // acct_9m4e2mr0ui3e8a215n4g\n\n    let factory_with_prefix = Factory::new(\"acct\")?;\n    let id = factory_with_prefix.generate();\n\n    println!(\"{}\", id); // acct_9m4e2mr0ui3e8a215n4g\n}\n```\n\n### GraphQL Support\n\nYou can use `Pxid` on GraphQL via the `async-graphql` crate.\nMake sure the `graphql` feature is enabled and import `Pxid` for GraphQL.\n\n```rust\nuse async_graphql::{Context, InputObject, Result, SimpleObject};\nuse pxid::graphql::Pxid;\n\n// -- snip --\n\n#[derive(Debug, InputObject)]\npub struct PostCreateInput {\n    pub title: String,\n    pub content: String,\n    pub parent_id: Option\u003cPxid\u003e,\n}\n\nimpl PostCreate {\n    pub async fn exec(ctx: \u0026Context\u003c'_\u003e, input: PostCreateInput) -\u003e Result\u003cSelf\u003e {\n// -- snip --\n```\n\n\u003e Check out the full example [here][2].\n\n## Layout\nA prefixed XID fits nicely on a 16 bytes slice thanks to its packed data format.\n\n\u003cdiv align=\"center\"\u003e\n  \u003ctable border=\"1\"\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e0\u003c/td\u003e\n      \u003ctd\u003e1\u003c/td\u003e\n      \u003ctd\u003e2\u003c/td\u003e\n      \u003ctd\u003e3\u003c/td\u003e\n      \u003ctd\u003e4\u003c/td\u003e\n      \u003ctd\u003e5\u003c/td\u003e\n      \u003ctd\u003e6\u003c/td\u003e\n      \u003ctd\u003e7\u003c/td\u003e\n      \u003ctd\u003e8\u003c/td\u003e\n      \u003ctd\u003e9\u003c/td\u003e\n      \u003ctd\u003e10\u003c/td\u003e\n      \u003ctd\u003e11\u003c/td\u003e\n      \u003ctd\u003e12\u003c/td\u003e\n      \u003ctd\u003e13\u003c/td\u003e\n      \u003ctd\u003e14\u003c/td\u003e\n      \u003ctd\u003e15\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd colspan=\"4\"\u003ePrefix\u003c/td\u003e\n      \u003ctd colspan=\"4\"\u003eTimestamp\u003c/td\u003e\n      \u003ctd colspan=\"3\"\u003eMachine ID\u003c/td\u003e\n      \u003ctd colspan=\"2\"\u003eProcess ID\u003c/td\u003e\n      \u003ctd colspan=\"3\"\u003eCounter\u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/table\u003e\n\u003c/div\u003e\n\nFor a total of 16 bytes.\n\nThe prefix allows up to 4 UTF-8 Characters, this allows the ID to provide some\ncontext about its scope.\n\n```txt\nacct_9m4e2mr0ui3e8a215n4g\nordr_9m4e2mr0ui3e8a215n4g\nusr_9m4e2mr0ui3e8a215n4g\n```\n\nThis way IDs are not only even harder to collide, but they also provides a bit\nof context on record association.\n\n## License\n\nThis project is licensed under the MIT License\n\n[1]: https://github.com/rs/xid\n[2]: https://github.com/whizzes/gabble/blob/ca10e295ce1386dd15a8f91f968e7aa8085287c4/crates/server/src/graphql/modules/post/mutation/post_create.rs\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwhizzes%2Fpxid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwhizzes%2Fpxid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwhizzes%2Fpxid/lists"}