#[derive(Facet)]
{
// Attributes available to this derive:
#[facet]
}
Expand description
Derive the Facet trait for structs, tuple structs, and enums.
Using this macro gives the derived type runtime (and to some extent, const-time) knowledge about the type, also known as “reflection”.
This uses unsynn, so it’s light, but it will choke on some Rust syntax because… there’s a lot of Rust syntax.
#[derive(Facet)]
struct FooBar {
foo: u32,
bar: String,
}§Container Attributes
#[derive(Facet)]
#[facet(rename_all = "kebab-case")]
struct FooBar {-
rename_all = ".."Rename all the fields (if this is a struct) or variants (if this is an enum) according to the given case convention. The possible values are:"snake_case","SCREAMING_SNAKE_CASE","PascalCase","camelCase","kebab-case","SCREAMING-KEBAB-CASE". -
transparentSerialize and deserialize a newtype struct exactly the same as if its single field were serialized and deserialized by itself. -
deny_unknown_fieldsAlways throw an error when encountering unknown fields during deserialization. When this attribute is not present unknown fields are ignored. -
skip_serializingDon’t allow this type to be serialized. -
skip_serializing_if = ".."Don’t allow this type to be serialized if the function returnstrue. -
invariants = ".."Called when doingWip::build. TODO
§Field Attributes
#[derive(Facet)]
struct FooBar {
#[facet(default)]
foo: u32,-
rename = ".."Rename to the given case convention. The possible values are:"snake_case","SCREAMING_SNAKE_CASE","PascalCase","camelCase","kebab-case","SCREAMING-KEBAB-CASE". -
defaultUse the field’s value from the container’sDefault::default()implementation when the field is missing during deserializing. -
default = ".."Use the expression when the field is missing during deserializing. -
sensitiveDon’t show the value in debug outputs. -
flattenFlatten the value’s content into the container structure. -
childMark as child node in a hierarchy. TODO -
skip_serializingIgnore when serializing. -
skip_serializing_if = ".."Ignore when serializing if the function returnstrue.
§Variant Attributes
#[derive(Facet)]
#[repr(C)]
enum FooBar {
#[facet(rename = "kebab-case")]
Foo(u32),-
rename = ".."Rename to the given case convention. The possible values are:"snake_case","SCREAMING_SNAKE_CASE","PascalCase","camelCase","kebab-case","SCREAMING-KEBAB-CASE". -
skip_serializingIgnore when serializing. -
skip_serializing_if = ".."Ignore when serializing if the function returnstrue.
§Examples
TODO.