{"id":20989898,"url":"https://github.com/iddm/unique-type-id","last_synced_at":"2025-05-14T18:32:19.389Z","repository":{"id":52453219,"uuid":"113652121","full_name":"iddm/unique-type-id","owner":"iddm","description":"A procedural macro for generating unique ids for rust types","archived":false,"fork":false,"pushed_at":"2024-02-28T22:49:28.000Z","size":75,"stargazers_count":14,"open_issues_count":3,"forks_count":7,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-26T09:35:24.954Z","etag":null,"topics":["procedural-macros","rust","types"],"latest_commit_sha":null,"homepage":null,"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/iddm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":"iddm"}},"created_at":"2017-12-09T07:47:55.000Z","updated_at":"2025-03-12T07:06:23.000Z","dependencies_parsed_at":"2023-12-05T17:21:12.679Z","dependency_job_id":"425a120e-0d81-41a7-8a0c-90a283653e1b","html_url":"https://github.com/iddm/unique-type-id","commit_stats":{"total_commits":45,"total_committers":7,"mean_commits":6.428571428571429,"dds":"0.33333333333333337","last_synced_commit":"cf65cf9bbe1df1fb8bb76ccde7c4b874f907a659"},"previous_names":["iddm/unique-type-id","vityafx/unique-type-id"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iddm%2Funique-type-id","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iddm%2Funique-type-id/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iddm%2Funique-type-id/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iddm%2Funique-type-id/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iddm","download_url":"https://codeload.github.com/iddm/unique-type-id/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253346983,"owners_count":21894273,"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":["procedural-macros","rust","types"],"created_at":"2024-11-19T06:26:38.031Z","updated_at":"2025-05-14T18:32:19.059Z","avatar_url":"https://github.com/iddm.png","language":"Rust","funding_links":["https://github.com/sponsors/iddm"],"categories":[],"sub_categories":[],"readme":"# unique-type-id\nA rust procedural macro crate for generating unique id for the rust types.\n\n[![Crates badge](https://img.shields.io/crates/v/unique_type_id.svg)](https://crates.io/crates/unique-type-id) \n[![CI](https://github.com/iddm/unique-type-id/actions/workflows/ci.yml/badge.svg)](https://github.com/iddm/unique-type-id/actions/workflows/ci.yml)\n[![Documentation](https://docs.rs/unique-type-id/badge.svg)](https://docs.rs/unique-type-id)\n[![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE)\n[![GitHub Sponsors](https://img.shields.io/github/sponsors/iddm)](https://github.com/sponsors/iddm)\n\n\n## What does it do?\n\nIt simply implements a trait for the type where is only one method - `id() -\u003e TypeId` which returns a unique positive number. For id generation, the procedural macro reads the file called \"types.toml\" and searches for the type name\nthere. You may also specify another file name if you want by using `UniqueTypeIdFile` attribute. Speaking more detailed:\n\n1. The procedural macro reads the attributes on a type.\n2. If there are no attributes, it uses `types.toml` file name as types file name, otherwise uses specified one.\n3. For each type the macro is used it tries to find the type name in the types file. If it can find it, it returns\nit's id, otherwise it returns the available id. Reading tests helps in understanding this.\n\n## Usage\n\n1. Add `unique-type-id` as dependency in your `Cargo.toml`:\n\n```toml\n[dependencies]\nunique-type-id = \"1\"\n```\n\n2. Create a struct or enum and use the trait:\n\n```rust\n#[test]\nfn unique_simple() {\n    use unique_type_id::UniqueTypeId;\n    #[derive(UniqueTypeId)]\n    struct Test1;\n    #[derive(UniqueTypeId)]\n    struct Test2;\n\n    assert_eq!(Test1::id().0, 1u64);\n    assert_eq!(Test2::id().0, 2u64);\n}\n```\n \nThis will generate a types file if it has not been created yet and put there ids, starting with `0`,\nfor each type which was not found there. This is how it looks when you have predefined set of ids\nfor your types:\n\n```rust\n#[test]\nfn unique_different_file() {\n    use unique_type_id::UniqueTypeId;\n    #[derive(UniqueTypeId)]\n    #[UniqueTypeIdFile = \"types2.toml\"]\n    struct Test1;\n    #[derive(UniqueTypeId)]\n    #[UniqueTypeIdFile = \"types2.toml\"]\n    struct Test2;\n\n    assert_eq!(Test1::id().0, 115u64);\n    assert_eq!(Test2::id().0, 232u64);\n}\n```\n\nHere we set up ids for our types manually by creating the `types2.toml` file.\n\n## Options\n\n- `UniqueTypeIdFile` - allows to specify the file name to write/read the IDs from.\n- `UniqueTypeIdType` - allows to change the ID number type from `u64` (the default) to the\nuser-preferred one.\n- `UniqueTypeIdStart` - allows to set the starting ID number for the type. Can be used if the\ntype layout file is very well-known and guaranteed to avoid collisions.\n\n### UniqueTypeIdFile\n\n```rust\n#[derive(UniqueTypeId)]\n#[UniqueTypeIdFile = \"types2.toml\"]\nstruct Test1;\n```\n\n### UniqueTypeIdType\n\n```rust\n#[derive(UniqueTypeId)]\n#[UniqueTypeIdType = \"i16\"]\nstruct Test;\n```\n\n### UniqueTypeIdStart\n\n```rust\n#[derive(UniqueTypeId)]\n#[UniqueTypeIdStart = \"23\"]\nstruct Test;\n```\n\n## Note\n\nDefault and custom type files are searched relatively to a directory where `cargo build` is called.\n \n## License\n\nThis project is [licensed under the MIT license](https://github.com/iddm/unique-type-id/blob/master/LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiddm%2Funique-type-id","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fiddm%2Funique-type-id","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiddm%2Funique-type-id/lists"}