struct_field_names
Provides StructFieldNames
derive macro.
generates
which can be used like
let field_one_name: &'static str = FIELD_NAMES.field_one;
println!;
.
This is useful mostly for typo-proofing.
Credits to the field_types crate. A lot of code here is copied from there.
Usage
Use the StructFieldNames
derive macro like this:
then access the field name as &'static str
like this:
let field_one_name: &'static str = FIELD_NAMES.field_one;
Use #[struct_field_names(skip)]
to skip fields.
With
SomeStruct::FIELD_NAMES.field_two
won't exist.
Visibility of the field names struct follows your struct.
With
only PublicStruct::FIELD_NAMES.public_field
would be available to the outside world.