FieldBuilder

Struct FieldBuilder 

Source
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

Source

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

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.

Source

pub const fn attributes(self, attributes: &'static [FieldAttribute]) -> Self

Sets the attributes for this field.

Source

pub const fn doc(self, doc: &'static [&'static str]) -> Self

Sets the documentation for this field.

Source

pub const fn flags(self, flags: FieldFlags) -> Self

Sets the flags for this field.

Source

pub const fn rename(self, rename: &'static str) -> Self

Sets the rename for this field.

Source

pub const fn alias(self, alias: &'static str) -> Self

Sets the alias for this field.

Source

pub const fn default_from_trait(self) -> Self

Sets the default to use the type’s Default trait.

Source

pub const fn default_custom(self, f: DefaultInPlaceFn) -> Self

Sets a custom default function.

Source

pub const fn skip_serializing_if(self, f: SkipSerializingIfFn) -> Self

Sets the skip_serializing_if predicate.

Source

pub const fn invariants(self, f: InvariantsFn) -> Self

Sets the invariants validation function.

Source

pub const fn proxy(self, proxy: &'static ProxyDef) -> Self

Sets the proxy definition for custom ser/de.

Source

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
Source

pub const fn build(self) -> Field

Builds the final Field instance.

Auto Trait Implementations§

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