struct-reflection-rs
A Rust library for obtaining struct field names at runtime through reflection-like capabilities.
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
Overview
This library provides a derive macro StructReflection that allows you to get field names from struct instances at runtime, which is useful for serialization, debugging, schema generation, and more.
Basic Usage
use StructReflection;
Features
- Get field names from named structs and tuple structs
- Support for generic structs
- Nested struct field reflection
- Array type handling
- Support for
Option<T>fields
Advanced Examples
Nested Structs
Array Fields
Generic Structs
Limitations
Currently, Option<T> fields are handled with a simplified approach that always returns a field with the optional suffix regardless of what T is. This is due to limitations in Rust's trait system and lack of specialization in stable Rust.