pub enum EnumRepr {
Flattened,
ExternallyTagged,
InternallyTagged {
tag: &'static str,
},
AdjacentlyTagged {
tag: &'static str,
content: &'static str,
},
}Expand description
How enum variants are represented in the serialized format.
Variants§
Flattened
Variant fields are flattened to the same level as other fields.
Also used for #[facet(untagged)] enums where there’s no tag at all.
Used by formats like KDL, TOML where all fields appear at one level.
Example: {"name": "...", "host": "...", "port": 8080}
ExternallyTagged
Variant name is a key, variant content is nested under it.
This is the default serde representation for enums.
Example: {"name": "...", "Tcp": {"host": "...", "port": 8080}}
InternallyTagged
Tag field is inside the content, alongside variant fields.
Used with #[facet(tag = "type")].
Example: {"type": "Tcp", "host": "...", "port": 8080}
AdjacentlyTagged
Tag and content are adjacent fields at the same level.
Used with #[facet(tag = "t", content = "c")].
Example: {"t": "Tcp", "c": {"host": "...", "port": 8080}}
Implementations§
Source§impl EnumRepr
impl EnumRepr
Sourcepub fn from_shape(shape: &'static Shape) -> Self
pub fn from_shape(shape: &'static Shape) -> Self
Detect the enum representation from a Shape’s attributes.
Returns:
Flattenedif#[facet(untagged)]InternallyTaggedif#[facet(tag = "...")]without contentAdjacentlyTaggedif both#[facet(tag = "...", content = "...")]ExternallyTaggedif no attributes (the default enum representation)