pub struct FieldBuilder { /* private fields */ }Expand description
Builder for constructing Field instances in const contexts.
This builder is primarily used by derive macros to generate more compact code.
All methods are const fn to allow usage in static/const contexts.
§Example
// For normal fields (default, most efficient):
const FIELD: Field = FieldBuilder::new(
"field_name",
<T as Facet>::SHAPE,
offset_of!(MyStruct, field_name)
).build();
// For recursive type fields (use lazy to break cycles):
const FIELD: Field = FieldBuilder::new_lazy(
"children",
|| <Vec<Self> as Facet>::SHAPE,
offset_of!(MyStruct, children)
).build();Implementations§
Source§impl FieldBuilder
impl FieldBuilder
Sourcepub const fn new(
name: &'static str,
shape: fn() -> &'static Shape,
offset: usize,
) -> Self
pub const fn new( name: &'static str, shape: fn() -> &'static Shape, offset: usize, ) -> Self
Creates a new FieldBuilder with a shape function.
The shape is provided as a function pointer to enable lazy evaluation, which improves compile times by deferring const evaluation to runtime.
Use the shape_of::<T> helper function for the common case:
FieldBuilder::new("field", shape_of::<i32>, offset)Sourcepub const fn new_lazy(
name: &'static str,
shape: fn() -> &'static Shape,
offset: usize,
) -> Self
pub const fn new_lazy( name: &'static str, shape: fn() -> &'static Shape, offset: usize, ) -> Self
Alias for new - kept for backward compatibility.
Previously used for recursive types, but now all fields use lazy shape references.
Sourcepub const fn attributes(self, attributes: &'static [FieldAttribute]) -> Self
pub const fn attributes(self, attributes: &'static [FieldAttribute]) -> Self
Sets the attributes for this field.
Sourcepub const fn doc(self, doc: &'static [&'static str]) -> Self
pub const fn doc(self, doc: &'static [&'static str]) -> Self
Sets the documentation for this field.
Sourcepub const fn flags(self, flags: FieldFlags) -> Self
pub const fn flags(self, flags: FieldFlags) -> Self
Sets the flags for this field.
Sourcepub const fn default_from_trait(self) -> Self
pub const fn default_from_trait(self) -> Self
Sets the default to use the type’s Default trait.
Sourcepub const fn default_custom(self, f: DefaultInPlaceFn) -> Self
pub const fn default_custom(self, f: DefaultInPlaceFn) -> Self
Sets a custom default function.
Sourcepub const fn skip_serializing_if(self, f: SkipSerializingIfFn) -> Self
pub const fn skip_serializing_if(self, f: SkipSerializingIfFn) -> Self
Sets the skip_serializing_if predicate.
Sourcepub const fn invariants(self, f: InvariantsFn) -> Self
pub const fn invariants(self, f: InvariantsFn) -> Self
Sets the invariants validation function.
Sourcepub const fn proxy(self, proxy: &'static ProxyDef) -> Self
pub const fn proxy(self, proxy: &'static ProxyDef) -> Self
Sets the proxy definition for custom ser/de.
Sourcepub const fn metadata(self, kind: &'static str) -> Self
pub const fn metadata(self, kind: &'static str) -> Self
Marks this field as storing metadata of the given kind.
Metadata fields are excluded from structural hashing and equality, and are populated by deserializers that support the metadata kind.
Common metadata kinds:
"span": Source byte offset and length"line": Source line number"column": Source column number