{"id":27205199,"url":"https://github.com/jofas/struct_field_names_as_array","last_synced_at":"2025-04-09T23:02:51.961Z","repository":{"id":44902035,"uuid":"414635702","full_name":"jofas/struct_field_names_as_array","owner":"jofas","description":"Procedural macro that generates an array of the field names of a named struct","archived":false,"fork":false,"pushed_at":"2024-11-26T12:52:29.000Z","size":94,"stargazers_count":34,"open_issues_count":6,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-28T22:35:26.614Z","etag":null,"topics":["macros","rust","rust-crate"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jofas.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-07T14:31:41.000Z","updated_at":"2025-03-26T00:04:04.000Z","dependencies_parsed_at":"2024-11-26T15:16:53.368Z","dependency_job_id":null,"html_url":"https://github.com/jofas/struct_field_names_as_array","commit_stats":{"total_commits":79,"total_committers":4,"mean_commits":19.75,"dds":"0.36708860759493667","last_synced_commit":"6b13713dca7502e8b2dc4250ef6b7c02d8bda5bd"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jofas%2Fstruct_field_names_as_array","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jofas%2Fstruct_field_names_as_array/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jofas%2Fstruct_field_names_as_array/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jofas%2Fstruct_field_names_as_array/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jofas","download_url":"https://codeload.github.com/jofas/struct_field_names_as_array/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248125581,"owners_count":21051768,"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":["macros","rust","rust-crate"],"created_at":"2025-04-09T23:01:06.446Z","updated_at":"2025-04-09T23:02:51.945Z","avatar_url":"https://github.com/jofas.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# struct-field-names-as-array\n\n[![Build Status](https://github.com/jofas/struct_field_names_as_array/actions/workflows/build.yml/badge.svg)](https://github.com/jofas/struct_field_names_as_array/actions/workflows/build.yml)\n[![Codecov](https://codecov.io/gh/jofas/struct_field_names_as_array/branch/master/graph/badge.svg?token=69YKZ1JIBK)](https://codecov.io/gh/jofas/struct_field_names_as_array)\n[![Latest Version](https://img.shields.io/crates/v/struct-field-names-as-array.svg)](https://crates.io/crates/struct-field-names-as-array)\n[![Downloads](https://img.shields.io/crates/d/struct-field-names-as-array?label=downloads)](https://crates.io/crates/struct-field-names-as-array)\n[![Docs](https://img.shields.io/badge/docs-latest-blue.svg)](https://docs.rs/struct-field-names-as-array/latest/struct_field_names_as_array)\n[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)\n\nProvides the `FieldNamesAsArray` and `FieldNamesAsSlice` traits and\nprocedural macros for deriving them.\nThe traits contain associated constants \n(`FieldNamesAsArray::FIELD_NAMES_AS_ARRAY` and `FieldNamesAsSlice::FIELD_NAMES_AS_SLICE`) \nlisting the field names of a struct.\n\n**Note:** The macros can only be derived from named structs.\n\n## Table of Contents\n\n\u003c!--ts--\u003e\n   * [Usage](#usage)\n   * [Attributes](#attributes)\n      * [Container Attributes](#container-attributes)\n         * [Rename all](#rename-all)\n      * [Field Attributes](#field-attributes)\n         * [Skip](#skip)\n         * [Rename](#rename)\n\u003c!--te--\u003e\n\n## Usage\n\nYou can derive the `FieldNamesAsArray` and `FieldNamesAsSlice` macros\nlike this:\n\n```rust\nuse struct_field_names_as_array::FieldNamesAsArray;\n\n#[derive(FieldNamesAsArray)]\nstruct Foo {\n    bar: String,\n    baz: String,\n    bat: String,\n}\n\nassert_eq!(Foo::FIELD_NAMES_AS_ARRAY, [\"bar\", \"baz\", \"bat\"]);\n```\n\n```rust\nuse struct_field_names_as_array::FieldNamesAsSlice;\n\n#[derive(FieldNamesAsSlice)]\nstruct Foo {\n    bar: String,\n    baz: String,\n    bat: String,\n}\n\nassert_eq!(Foo::FIELD_NAMES_AS_SLICE, [\"bar\", \"baz\", \"bat\"]);\n```\n\n## Attributes\n\nThe `FieldNamesAsArray` macro comes with the\n`field_names_as_array` attribute.\nOrthogonally, `FieldNamesAsSlice` supports the `field_names_as_slice`\nattribute with the same arguments.\nThe arguments are listed below.\n\n### Container Attributes\n\nContainer attributes are global attributes that change the behavior\nof the whole field names collection, rather than that of a single field.\n\n#### Rename all\n\nThe `rename_all` attribute renames every field of the struct according\nto the provided naming convention.\nThis attribute works exactly like the [serde][serde_rename_all]\nequivalent.\nSupported are these naming conventions:\n\n  - `lowercase`\n  - `UPPERCASE`\n  - `PascalCase`\n  - `camelCase`\n  - `snake_case`\n  - `SCREAMING_SNAKE_CASE`\n  - `kebab-case`\n  - `SCREAMING-KEBAB-CASE`\n\n```rust\nuse struct_field_names_as_array::FieldNamesAsArray;\n\n#[derive(FieldNamesAsArray)]\n#[field_names_as_array(rename_all = \"SCREAMING-KEBAB-CASE\")]\nstruct Foo {\n    field_one: String,\n    field_two: String,\n    field_three: String,\n}\n\nassert_eq!(\n  Foo::FIELD_NAMES_AS_ARRAY, \n  [\"FIELD-ONE\", \"FIELD-TWO\", \"FIELD-THREE\"],\n);\n```\n\n**Note:** Same as serde's implementation of `rename_all`, it is\nassumed that your field names follow the rust naming convention.\nNamely, all field names must be given in `snake_case`.\nIf you don't follow this convention, applying `rename_all` may result \nin unexpected field names.\n\n### Field Attributes\n\nField attributes can be added to the fields of a named struct and \nchange the behavior of a single field.\n\n#### Skip\n\nThe `skip` attribute removes the field from the generated constant.\n\n```rust\nuse struct_field_names_as_array::FieldNamesAsSlice;\n\n#[derive(FieldNamesAsSlice)]\nstruct Foo {\n    bar: String,\n    baz: String,\n    #[field_names_as_slice(skip)]\n    bat: String,\n}\n\nassert_eq!(Foo::FIELD_NAMES_AS_SLICE, [\"bar\", \"baz\"]);\n```\n\n#### Rename\n\nThe `rename` attribute renames the field in the generated constant.\n\n```rust\nuse struct_field_names_as_array::FieldNamesAsArray;\n\n#[derive(FieldNamesAsArray)]\nstruct Foo {\n    bar: String,\n    baz: String,\n    #[field_names_as_array(rename = \"foo\")]\n    bat: String,\n}\n\nassert_eq!(Foo::FIELD_NAMES_AS_ARRAY, [\"bar\", \"baz\", \"foo\"]);\n```\n\n[serde_rename_all]: https://serde.rs/container-attrs.html#rename_all\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjofas%2Fstruct_field_names_as_array","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjofas%2Fstruct_field_names_as_array","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjofas%2Fstruct_field_names_as_array/lists"}