pub struct FieldKey<'de> {
pub name: Option<Cow<'de, str>>,
pub location: FieldLocationHint,
pub doc: Option<Vec<Cow<'de, str>>>,
pub tag: Option<Cow<'de, str>>,
}Expand description
Field key for a serialized field.
For self-describing formats, this represents either:
- A named key (struct field or map key with string name)
- A tagged key (e.g.,
@stringin Styx for type pattern keys) - A unit key (map key with no name, e.g.,
@in Styx representingNoneinOption<String>keys)
Fields§
§name: Option<Cow<'de, str>>Field name.
None represents a unit key (e.g., @ in Styx) which can be deserialized as
None for Option<String> map keys. For struct field deserialization, None
is an error since struct fields always have names.
location: FieldLocationHintLocation hint.
doc: Option<Vec<Cow<'de, str>>>Documentation comments attached to this field (for formats that support them).
Used by formats like Styx where /// comment before a field is preserved.
When deserializing into a metadata_container type like Documented<T>,
these doc lines are used to populate the metadata.
tag: Option<Cow<'de, str>>Tag name for tagged keys (for formats that support them).
Used by formats like Styx where @string in key position represents a type pattern.
When deserializing into a metadata_container type with #[facet(metadata = "tag")],
this tag name is used to populate the metadata.
None: not a tagged key (bare identifier likename)Some(""): unit tag (@alone)Some("string"): named tag (@string)
Implementations§
Source§impl<'de> FieldKey<'de>
impl<'de> FieldKey<'de>
Sourcepub fn new(name: impl Into<Cow<'de, str>>, location: FieldLocationHint) -> Self
pub fn new(name: impl Into<Cow<'de, str>>, location: FieldLocationHint) -> Self
Create a new field key with a name.
Sourcepub fn with_doc(
name: impl Into<Cow<'de, str>>,
location: FieldLocationHint,
doc: Vec<Cow<'de, str>>,
) -> Self
pub fn with_doc( name: impl Into<Cow<'de, str>>, location: FieldLocationHint, doc: Vec<Cow<'de, str>>, ) -> Self
Create a new field key with a name and documentation.
Sourcepub fn tagged(
tag: impl Into<Cow<'de, str>>,
location: FieldLocationHint,
) -> Self
pub fn tagged( tag: impl Into<Cow<'de, str>>, location: FieldLocationHint, ) -> Self
Create a tagged field key (e.g., @string in Styx).
Used for type pattern keys where the key is a tag rather than a bare identifier.
Sourcepub fn tagged_with_doc(
tag: impl Into<Cow<'de, str>>,
location: FieldLocationHint,
doc: Vec<Cow<'de, str>>,
) -> Self
pub fn tagged_with_doc( tag: impl Into<Cow<'de, str>>, location: FieldLocationHint, doc: Vec<Cow<'de, str>>, ) -> Self
Create a tagged field key with documentation.
Sourcepub fn unit(location: FieldLocationHint) -> Self
pub fn unit(location: FieldLocationHint) -> Self
Create a unit field key (no name).
Used for formats like Styx where @ represents a unit key in maps.
This is equivalent to tagged("") - a tag with an empty name.
Sourcepub fn unit_with_doc(
location: FieldLocationHint,
doc: Vec<Cow<'de, str>>,
) -> Self
pub fn unit_with_doc( location: FieldLocationHint, doc: Vec<Cow<'de, str>>, ) -> Self
Create a unit field key with documentation.