structype_derive 1.0.0

A derive macro crate that lets you view an allowed type's fields and will let you over-ride it.
Documentation

This is a derive procedural macro that will let you add custom derive and attributes over structs and enums. This derive will add two impl on the type. as_string() returns a json serialized string key-value representation where key is the type's field name and value is the attribute set in the structype_label, whileprint_fields() function will print the same to STDOUT. This macro cannot be applied over tuple structs and unit structs, so it will panic if these types are annotated with this derive and won't let you compile.

Example:

use structype_derive::StrucType;

#[derive(StrucType)]
// #[structype_label = "over_ride name"] // This will panic the macro
struct MyStruct {
#[structype_label = "Overridde name for string"]
_my_string: String,
#[structype_label = "int_override"]
_my_int64: i64,
_my_float: f64,
_my_nested_struct: MyNestedStruct,
}

#[derive(StrucType)]
struct MyNestedStruct {
_my_nested_struct_string: String,
}

fn print_struct_fields() {
MyStruct::print_fields();
let data = MyStruct::as_string();
println!("{}", data);
MyNestedStruct::print_fields();
let data = MyNestedStruct::as_string();
println!("{}", data);
}

The above will generate and return a json serialized string representation where the key is the struct's field name and the value is the structype_label's value. If the structype_label is absent, the value will be the same as that of the key.

Output:

{
"_my_string": "Overridde name for string",
"_my_int64": "int_override",
"_my_float": "_my_float",
"_my_nested_struct": "_my_nested_struct"
}