{"id":17874287,"url":"https://github.com/modprog/attribute-derive","last_synced_at":"2025-03-21T22:31:49.808Z","repository":{"id":57501087,"uuid":"454850691","full_name":"ModProg/attribute-derive","owner":"ModProg","description":null,"archived":false,"fork":false,"pushed_at":"2024-03-23T16:33:36.000Z","size":152,"stargazers_count":14,"open_issues_count":13,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-04-24T19:33:46.937Z","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/ModProg.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":"2022-02-02T16:29:04.000Z","updated_at":"2024-06-22T19:09:20.458Z","dependencies_parsed_at":"2023-02-18T20:15:28.544Z","dependency_job_id":"49b84658-f799-4c16-9858-71413df4a7fb","html_url":"https://github.com/ModProg/attribute-derive","commit_stats":{"total_commits":31,"total_committers":1,"mean_commits":31.0,"dds":0.0,"last_synced_commit":"0679258c14b1243bcea32947e45c6c5077bc4bcb"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ModProg%2Fattribute-derive","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ModProg%2Fattribute-derive/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ModProg%2Fattribute-derive/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ModProg%2Fattribute-derive/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ModProg","download_url":"https://codeload.github.com/ModProg/attribute-derive/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244880315,"owners_count":20525506,"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-28T11:08:21.459Z","updated_at":"2025-03-21T22:31:49.308Z","avatar_url":"https://github.com/ModProg.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# attribute-derive\n\n[![docs.rs](https://img.shields.io/docsrs/attribute-derive)](https://docs.rs/attribute-derive/latest/attribute_derive/)\n[![lib.rs](https://img.shields.io/crates/v/attribute-derive)](https://lib.rs/crates/attribute-derive)\n[![MIT](https://img.shields.io/crates/l/attribute-derive)](LICENSE)\n[![Documentation for `main`](https://img.shields.io/badge/docs-main-informational)](https://modprog.github.io/attribute-derive/attribute_derive/)\n\nBasically clap for attribute macros:\n```rust\nuse attribute_derive::Attribute;\nuse syn::Type;\n\n#[derive(Attribute)]\n#[attribute(ident = collection)]\n#[attribute(error(missing_field = \"`{field}` was not specified\"))]\nstruct CollectionAttribute {\n    // Options are optional by default (will be set to None if not specified)\n    authority: Option\u003cString\u003e,\n    name: String,\n    // Any type implementing default can be flagged as default\n    // This will be set to Vec::default() when not specified\n    #[attribute(optional)]\n    views: Vec\u003cType\u003e,\n    // Booleans can be used without assigning a value, i.e., as a flag.\n    // If omitted they are set to false\n    some_flag: bool,\n}\n```\n\nWill be able to parse an attribute like this:\n```rust\n#[collection(authority=\"Some String\", name = r#\"Another string\"#, views = [Option, ()])]\n```\n\n## Limitations\n\nThere are some limitations in syntax parsing that will be lifted future releases.\n\n- literals in top level (meaning something like `#[attr(42, 3.14, \"hi\")]`\n- function like arguments (something like `#[attr(view(a = \"test\"))]`\n- other syntaxes, maybe something like `key: value`\n\n## Parse methods\n\nThere are multiple ways of parsing a struct deriving [`Attribute`](https://docs.rs/attribute-derive/latest/attribute_derive/trait.Attribute.html).\n\nFor helper attributes there is:\n- [`Attribute::from_attributes`](https://docs.rs/attribute-derive/latest/attribute_derive/trait.Attribute.html#tymethod.from_attributes) which takes in an [`IntoIterator\u003cItem = \u0026'a\nsyn::Attribute`](https://docs.rs/syn/latest/syn/struct.Attribute.html)\n(e.g. a [`\u0026Vec\u003csyn::Attribute\u003e`](https://docs.rs/syn/latest/syn/struct.Attribute.html)). Most useful for derive macros.\n- [`Attribute::remove_attributes`](https://docs.rs/attribute-derive/latest/attribute_derive/trait.Attribute.html#tymethod.remove_attributes) which takes an [`\u0026mut Vec\u003csyn::Attribute\u003e`](https://docs.rs/syn/latest/syn/struct.Attribute.html)\nand does not only parse the [`Attribute`](https://docs.rs/attribute-derive/latest/attribute_derive/trait.Attribute.html#tymethod.from_attributes) but also removes those matching. Useful for helper\nattributes for proc macros, where the helper attributes need to be removed.\n\nFor parsing a single [`TokenStream`](https://docs.rs/proc-macro2/latest/proc_macro2/struct.TokenStream.html) e.g. for parsing the proc macro input there a two ways:\n\n- [`Attribute::from_args`](https://docs.rs/attribute-derive/latest/attribute_derive/trait.Attribute.html#tymethod.from_args) taking in a [`TokenStream`](https://docs.rs/proc-macro2/latest/proc_macro2/struct.TokenStream.html)\n- As `derive(Attribute)` also derives [`Parse`](https://docs.rs/syn/latest/syn/parse/trait.Parse.html) so you can use the [parse](https://docs.rs/syn/latest/syn/parse/index.html) API,\ne.g. with [`parse_macro_input!(tokens as Attribute)`](https://docs.rs/syn/latest/syn/macro.parse_macro_input.html).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmodprog%2Fattribute-derive","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmodprog%2Fattribute-derive","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmodprog%2Fattribute-derive/lists"}