Field

Struct Field 

Source
#[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 str

key for the struct field (for tuples and tuple-structs, this is the 0-based index)

§shape: ShapeRef

shape 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: usize

offset of the field in the struct (obtained through core::mem::offset_of)

§flags: FieldFlags

Bit 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 (for Spanned<T>)
  • "line": Source line number
  • "column": Source column number

Implementations§

Source§

impl Field

Source

pub fn is_flattened(&self) -> bool

Returns true if this field is flattened.

This checks the FLATTEN flag (O(1)).

Source

pub fn is_sensitive(&self) -> bool

Returns true if this field is marked as sensitive.

This checks the SENSITIVE flag (O(1)).

Source

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).

Source

pub fn default_source(&self) -> Option<&DefaultSource>

Returns the default source for this field, if any.

Source

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)).

Source

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.

Source

pub fn metadata_kind(&self) -> Option<&'static str>

Returns the metadata kind if this field stores metadata.

Common values: "span", "line", "column"

Source

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)).

Source

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

Source

pub fn shape(&self) -> &'static Shape

Returns the shape of the inner type

Source

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.

Source

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.

Source

pub fn has_builtin_attr(&self, key: &str) -> bool

Checks whether the Field has a builtin attribute with the given key.

Source

pub fn get_builtin_attr(&self, key: &str) -> Option<&Attr>

Gets a builtin attribute by key.

Source

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)
Source

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.

Source

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_SERIALIZING flag set, or
  • skip_serializing_if is set and the predicate returns true
§Safety

field_ptr must point to a valid value of this field’s type.

Source

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.

Source

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).

Source

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).

Trait Implementations§

Source§

impl Clone for Field

Source§

fn clone(&self) -> Field

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Field

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Copy for Field

Auto Trait Implementations§

§

impl Freeze for Field

§

impl RefUnwindSafe for Field

§

impl Send for Field

§

impl Sync for Field

§

impl Unpin for Field

§

impl UnwindSafe for Field

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.