#[repr(C)]pub struct Field {Show 13 fields
pub name: &'static str,
pub shape: ShapeRef,
pub offset: usize,
pub flags: FieldFlags,
pub rename: Option<&'static str>,
pub alias: Option<&'static str>,
pub attributes: &'static [FieldAttribute],
pub doc: &'static [&'static str],
pub default: Option<DefaultSource>,
pub skip_serializing_if: Option<SkipSerializingIfFn>,
pub invariants: Option<InvariantsFn>,
pub proxy: Option<&'static ProxyDef>,
pub metadata: Option<&'static str>,
}Expand description
Describes a field in a struct or tuple
Fields§
§name: &'static strkey for the struct field (for tuples and tuple-structs, this is the 0-based index)
shape: ShapeRefshape of the inner type
ShapeRef wraps a function that returns the shape, enabling lazy evaluation
for recursive types while still being simple to use.
offset: usizeoffset of the field in the struct (obtained through core::mem::offset_of)
flags: FieldFlagsBit flags for common boolean attributes.
Provides O(1) access to frequently-checked attributes like sensitive,
flatten, skip, etc. These are set by the derive macro based on
#[facet(...)] attributes with #[storage(flag)] in the grammar.
rename: Option<&'static str>Renamed field name for serialization/deserialization.
Set by #[facet(rename = "name")]. When present, serializers/deserializers
should use this name instead of the field’s actual name.
alias: Option<&'static str>Alternative name(s) accepted during deserialization.
Set by #[facet(alias = "name")]. During deserialization, this name
is accepted in addition to the primary name (or renamed name).
attributes: &'static [FieldAttribute]arbitrary attributes set via the derive macro
This slice contains extension attributes that don’t have dedicated storage.
Builtin attributes with #[storage(flag)] or #[storage(field)] are stored
in their dedicated fields instead.
doc: &'static [&'static str]doc comments
default: Option<DefaultSource>Default value source for this field.
Set by #[facet(default)] or #[facet(default = expr)].
skip_serializing_if: Option<SkipSerializingIfFn>Predicate to conditionally skip serialization of this field.
Set by #[facet(skip_serializing_if = fn_name)].
invariants: Option<InvariantsFn>Type invariant validation function for this field.
Set by #[facet(invariants = fn_name)].
proxy: Option<&'static ProxyDef>Proxy definition for custom serialization/deserialization.
Set by #[facet(proxy = ProxyType)].
metadata: Option<&'static str>Metadata kind for this field, if it stores metadata.
Set by #[facet(metadata = kind)] (e.g., #[facet(metadata = span)]).
Metadata fields are:
- Excluded from structural hashing (
Peek::structural_hash) - Excluded from structural equality comparisons
- Excluded from tree diffing
- Populated by deserializers that support the metadata kind
Common metadata kinds:
"span": Source byte offset and length (forSpanned<T>)"line": Source line number"column": Source column number
Implementations§
Source§impl Field
impl Field
Sourcepub fn is_flattened(&self) -> bool
pub fn is_flattened(&self) -> bool
Returns true if this field is flattened.
This checks the FLATTEN flag (O(1)).
Sourcepub fn is_sensitive(&self) -> bool
pub fn is_sensitive(&self) -> bool
Returns true if this field is marked as sensitive.
This checks the SENSITIVE flag (O(1)).
Sourcepub fn has_default(&self) -> bool
pub fn has_default(&self) -> bool
Returns true if this field has a default value.
This returns true for both #[facet(default)] (uses the type’s Default impl)
and #[facet(default = expr)] (uses a custom expression).
Sourcepub fn default_source(&self) -> Option<&DefaultSource>
pub fn default_source(&self) -> Option<&DefaultSource>
Returns the default source for this field, if any.
Sourcepub fn is_child(&self) -> bool
pub fn is_child(&self) -> bool
Returns true if this field is a child (for KDL/XML formats).
This checks the CHILD flag (O(1)).
Sourcepub fn is_metadata(&self) -> bool
pub fn is_metadata(&self) -> bool
Returns true if this field stores metadata.
Metadata fields are excluded from structural hashing and equality.
Use metadata_kind() to get the specific kind of metadata.
Sourcepub fn metadata_kind(&self) -> Option<&'static str>
pub fn metadata_kind(&self) -> Option<&'static str>
Returns the metadata kind if this field stores metadata.
Common values: "span", "line", "column"
Sourcepub fn should_skip_deserializing(&self) -> bool
pub fn should_skip_deserializing(&self) -> bool
Returns true if this field should be skipped during deserialization.
This checks the SKIP and SKIP_DESERIALIZING flags (O(1)).
Sourcepub fn effective_name(&self) -> &'static str
pub fn effective_name(&self) -> &'static str
Returns the effective name for this field during serialization/deserialization.
Returns rename if set, otherwise returns the field’s actual name.
Source§impl Field
impl Field
Sourcepub fn has_attr(&self, ns: Option<&str>, key: &str) -> bool
pub fn has_attr(&self, ns: Option<&str>, key: &str) -> bool
Checks whether the Field has an attribute with the given namespace and key.
Use None for builtin attributes, Some("ns") for namespaced attributes.
Sourcepub fn get_attr(&self, ns: Option<&str>, key: &str) -> Option<&Attr>
pub fn get_attr(&self, ns: Option<&str>, key: &str) -> Option<&Attr>
Gets an attribute by namespace and key.
Use None for builtin attributes, Some("ns") for namespaced attributes.
Sourcepub fn has_builtin_attr(&self, key: &str) -> bool
pub fn has_builtin_attr(&self, key: &str) -> bool
Checks whether the Field has a builtin attribute with the given key.
Sourcepub fn get_builtin_attr(&self, key: &str) -> Option<&Attr>
pub fn get_builtin_attr(&self, key: &str) -> Option<&Attr>
Gets a builtin attribute by key.
Sourcepub fn proxy(&self) -> Option<&'static ProxyDef>
pub fn proxy(&self) -> Option<&'static ProxyDef>
Gets the proxy definition, if present.
This is set when #[facet(proxy = ProxyType)] is used. The proxy type
is used for both serialization and deserialization. The user must implement:
TryFrom<ProxyType> for FieldType(for deserialization)TryFrom<&FieldType> for ProxyType(for serialization)
Sourcepub fn proxy_shape(&self) -> Option<&'static Shape>
pub fn proxy_shape(&self) -> Option<&'static Shape>
Gets the proxy shape, if present.
Convenience method that returns just the shape from the proxy definition.
Sourcepub unsafe fn should_skip_serializing(&self, field_ptr: PtrConst) -> bool
pub unsafe fn should_skip_serializing(&self, field_ptr: PtrConst) -> bool
Checks if this field should be skipped during serialization.
Returns true if:
- The field has
SKIP_SERIALIZINGflag set, or skip_serializing_ifis set and the predicate returns true
§Safety
field_ptr must point to a valid value of this field’s type.
Sourcepub fn has_proxy(&self) -> bool
pub fn has_proxy(&self) -> bool
Returns true if this field has a proxy for custom ser/de.
When true, use proxy() to get the proxy definition which contains
the proxy shape and conversion functions.
Sourcepub fn proxy_convert_in_fn(&self) -> Option<ProxyConvertInFn>
pub fn proxy_convert_in_fn(&self) -> Option<ProxyConvertInFn>
Gets the proxy convert_in function, if present.
This converts from proxy type to target type (deserialization).
Sourcepub fn proxy_convert_out_fn(&self) -> Option<ProxyConvertOutFn>
pub fn proxy_convert_out_fn(&self) -> Option<ProxyConvertOutFn>
Gets the proxy convert_out function, if present.
This converts from target type to proxy type (serialization).