field-kinds
Compile-time struct field introspection for Rust.
Features
- Field names - Get field names as
&'static str - Serialized names - Supports
#[serde(rename)]and#[serde(rename_all)] - Type categories - Automatic categorization: numeric, text, bool, optional, collection
- Custom tags - Add arbitrary tags via
#[field_tags("tag1", "tag2")] - Static metadata - All field info available as
const FIELDS: &'static [FieldMeta] - Zero runtime cost - All metadata computed at compile time
Installation
[]
= "0.2"
Quick Start
use ;
Attributes
Struct-level
| Attribute | Description |
|---|---|
#[serde(rename_all = "...")] |
Apply case conversion to serialized names |
Supported cases: camelCase, snake_case, PascalCase, SCREAMING_SNAKE_CASE, kebab-case
Field-level
| Attribute | Description |
|---|---|
#[serde(rename = "...")] |
Override serialized name |
#[field_tags("tag1", "tag2")] |
Add custom tags |
#[field_kinds(skip)] |
Exclude field from introspection |
Type Categories
Types are automatically categorized:
| Category | Types |
|---|---|
numeric |
i8-i128, u8-u128, f32, f64, isize, usize |
text |
String, &str, Box<str>, char |
bool |
bool |
optional |
Option<T> |
collection |
Vec<T>, HashSet<T>, HashMap<K,V>, BTreeSet<T>, BTreeMap<K,V>, [T; N], &[T] |
unknown |
Everything else |
Custom Categories
Implement Categorized for your types:
use ;
;
MSRV
Minimum supported Rust version is 1.90.0 (Rust 2024 edition).
License
MIT