{"id":17308628,"url":"https://github.com/teddriggs/field_names","last_synced_at":"2025-04-14T13:45:42.288Z","repository":{"id":55085912,"uuid":"327950541","full_name":"TedDriggs/field_names","owner":"TedDriggs","description":"proc-macro for accessing struct field names at runtime","archived":false,"fork":false,"pushed_at":"2022-01-10T16:55:45.000Z","size":12,"stargazers_count":38,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-09T10:15:47.768Z","etag":null,"topics":["proc-macro","rust"],"latest_commit_sha":null,"homepage":"","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/TedDriggs.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}},"created_at":"2021-01-08T16:10:32.000Z","updated_at":"2025-03-18T04:16:00.000Z","dependencies_parsed_at":"2022-08-14T11:31:17.155Z","dependency_job_id":null,"html_url":"https://github.com/TedDriggs/field_names","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TedDriggs%2Ffield_names","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TedDriggs%2Ffield_names/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TedDriggs%2Ffield_names/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TedDriggs%2Ffield_names/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TedDriggs","download_url":"https://codeload.github.com/TedDriggs/field_names/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248890507,"owners_count":21178448,"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":["proc-macro","rust"],"created_at":"2024-10-15T12:05:38.587Z","updated_at":"2025-04-14T13:45:42.258Z","avatar_url":"https://github.com/TedDriggs.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# field_names\n\n[![Build Status](https://github.com/TedDriggs/field_names/workflows/CI/badge.svg)](https://github.com/TedDriggs/field_names/actions)\n[![Latest Version](https://img.shields.io/crates/v/field_names.svg)](https://crates.io/crates/field_names)\n\n`field_names` is a Rust crate to expose a field or variant names from source code as strings at runtime.\n\n# Example\n\nConsider a simple struct such as this one.\n\n```rust\n#[derive(FieldNames)]\nstruct Example {\n    hello: String,\n    world: String,\n    #[field_names(skip)]\n    ignore_me: bool,\n}\n```\n\n`field_names` will emit the following:\n\n```rust\n#[automatically_derived]\nimpl Example {\n    const FIELDS: [\u0026'static str; 2] = [\n        \"hello\",\n        \"world\",\n    ];\n}\n```\n\nEnums are the same:\n\n```rust\n#[derive(VariantNames)]\nenum Example {\n    Hello(String),\n    #[variant_names(skip)]\n    Secret(String),\n    World,\n}\n```\n\n`field_names` will emit the following:\n\n```rust\n#[automatically_derived]\nimpl Example {\n    const VARIANTS: [\u0026'static str; 2] = [\n        \"Hello\",\n        \"World\",\n    ];\n}\n```\n\n# Uses\n\nThis crate was originally created for a case where a set of rules were being read at runtime which referenced fields of structs elsewhere in the code base.\nThe referenced struct exposed a method which had a `match` statement to go from strings to its fields, but there was not a way to ensure the arms of that match statement stayed in sync with the struct definition.\nWith this crate, a unit test could be created to ensure that every field on the struct - except those deliberately omitted - was handled by the method.\n\nThis crate can also be used to enforce relationships among structs and enums at unit-test time that cannot be expressed at compile-time.\nSee `tests/keep_in_sync` for an example and explanation of that scenario.\n\n# FAQs\n\n### Why aren't `FieldNames` and `VariantNames` traits?\n\nUsing `field_names` is an implementation convenience; it shouldn't force you to change your crate's public API.\n\n### How do I make `FIELDS` or `VARIANTS` public?\n\nYou can add your own inherent method, e.g. `fields() -\u003e \u0026[\u0026'static str]`, or define a trait that matches your use-case and reference `FIELDS` in the trait implementation.\n\n### Can I get field names for an enum variant?\n\nThis currently isn't supported, using newtype variants and separate structs per variant is currently the recommended approach.\nYou can use the [`from_variants`](https://crates.io/crates/from_variants) crate to auto-generate conversions from those structs into the enum.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fteddriggs%2Ffield_names","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fteddriggs%2Ffield_names","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fteddriggs%2Ffield_names/lists"}