pub struct ShapeBuilder { /* private fields */ }Expand description
Implementations§
Source§impl ShapeBuilder
impl ShapeBuilder
Sourcepub const fn for_sized<T>(type_identifier: &'static str) -> ShapeBuilder
pub const fn for_sized<T>(type_identifier: &'static str) -> ShapeBuilder
Create a new builder for a sized type.
The id and layout are derived from the type parameter.
Sourcepub const fn for_unsized<T>(type_identifier: &'static str) -> ShapeBuilderwhere
T: ?Sized,
pub const fn for_unsized<T>(type_identifier: &'static str) -> ShapeBuilderwhere
T: ?Sized,
Create a new builder for an unsized type.
Sourcepub const fn vtable(self, vtable: VTableErased) -> ShapeBuilder
pub const fn vtable(self, vtable: VTableErased) -> ShapeBuilder
Set the vtable (type-erased).
Sourcepub const fn vtable_direct(self, vtable: &'static VTableDirect) -> ShapeBuilder
pub const fn vtable_direct(self, vtable: &'static VTableDirect) -> ShapeBuilder
Set the vtable from a direct vtable reference.
Sourcepub const fn vtable_indirect(
self,
vtable: &'static VTableIndirect,
) -> ShapeBuilder
pub const fn vtable_indirect( self, vtable: &'static VTableIndirect, ) -> ShapeBuilder
Set the vtable from an indirect vtable reference.
Sourcepub const fn type_ops(self, type_ops: TypeOps) -> ShapeBuilder
pub const fn type_ops(self, type_ops: TypeOps) -> ShapeBuilder
Set the per-type operations (drop, default, clone) using the erased enum.
For generic containers, use this to provide the monomorphized operations while sharing the main vtable across all instantiations.
Sourcepub const fn type_ops_direct(
self,
type_ops: &'static TypeOpsDirect,
) -> ShapeBuilder
pub const fn type_ops_direct( self, type_ops: &'static TypeOpsDirect, ) -> ShapeBuilder
Set per-type operations for concrete types (uses thin pointers).
Use this for scalars, String, and derived structs/enums.
Sourcepub const fn type_ops_indirect(
self,
type_ops: &'static TypeOpsIndirect,
) -> ShapeBuilder
pub const fn type_ops_indirect( self, type_ops: &'static TypeOpsIndirect, ) -> ShapeBuilder
Set per-type operations for generic containers (uses wide pointers).
Use this for Vec<T>, Option<T>, Arc<T>, etc.
Sourcepub const fn add_marker_trait(self, trait_flag: MarkerTraits) -> ShapeBuilder
pub const fn add_marker_trait(self, trait_flag: MarkerTraits) -> ShapeBuilder
Add a marker trait flag.
Sourcepub const fn marker_traits(self, traits: MarkerTraits) -> ShapeBuilder
pub const fn marker_traits(self, traits: MarkerTraits) -> ShapeBuilder
Set all marker traits at once using combined bitflags.
Sourcepub const fn eq(self) -> ShapeBuilder
pub const fn eq(self) -> ShapeBuilder
Mark type as implementing Eq.
Sourcepub const fn copy(self) -> ShapeBuilder
pub const fn copy(self) -> ShapeBuilder
Mark type as implementing Copy.
Sourcepub const fn send(self) -> ShapeBuilder
pub const fn send(self) -> ShapeBuilder
Mark type as implementing Send.
Sourcepub const fn sync(self) -> ShapeBuilder
pub const fn sync(self) -> ShapeBuilder
Mark type as implementing Sync.
Sourcepub const fn unpin(self) -> ShapeBuilder
pub const fn unpin(self) -> ShapeBuilder
Mark type as implementing Unpin.
Sourcepub const fn unwind_safe(self) -> ShapeBuilder
pub const fn unwind_safe(self) -> ShapeBuilder
Mark type as implementing UnwindSafe.
Sourcepub const fn ref_unwind_safe(self) -> ShapeBuilder
pub const fn ref_unwind_safe(self) -> ShapeBuilder
Mark type as implementing RefUnwindSafe.
Sourcepub const fn ty(self, ty: Type) -> ShapeBuilder
pub const fn ty(self, ty: Type) -> ShapeBuilder
Set the type.
Sourcepub const fn def(self, def: Def) -> ShapeBuilder
pub const fn def(self, def: Def) -> ShapeBuilder
Set the definition.
Sourcepub const fn module_path(self, module_path: &'static str) -> ShapeBuilder
pub const fn module_path(self, module_path: &'static str) -> ShapeBuilder
Set the module path where this type is defined.
This is typically set to module_path!() by the derive macro,
which expands to the module path at the definition site.
Sourcepub const fn decl_id(self, decl_id: DeclId) -> ShapeBuilder
pub const fn decl_id(self, decl_id: DeclId) -> ShapeBuilder
Set the declaration identifier.
The DeclId identifies the type declaration independent of type
parameters. For derive macros, this is typically computed from the
source location and type name.
For non-generic types (no type parameters), you don’t need to call this - the decl_id will be automatically computed from the type identifier.
For generic foreign types, just set module_path and
the decl_id will be auto-computed from @module_path#kind#type_identifier.
See DeclId for stability guarantees (spoiler: there are none).
Sourcepub const fn source_file(self, file: &'static str) -> ShapeBuilder
pub const fn source_file(self, file: &'static str) -> ShapeBuilder
Set the source file where this type is defined.
This is typically set to file!() by the derive macro
when the doc feature is enabled.
Sourcepub const fn source_line(self, line: u32) -> ShapeBuilder
pub const fn source_line(self, line: u32) -> ShapeBuilder
Set the source line number where this type is defined.
This is typically set to line!() by the derive macro
when the doc feature is enabled.
Sourcepub const fn source_column(self, column: u32) -> ShapeBuilder
pub const fn source_column(self, column: u32) -> ShapeBuilder
Set the source column number where this type is defined.
This is typically set to column!() by the derive macro
when the doc feature is enabled.
Sourcepub const fn type_params(
self,
type_params: &'static [TypeParam],
) -> ShapeBuilder
pub const fn type_params( self, type_params: &'static [TypeParam], ) -> ShapeBuilder
Set the type parameters.
Sourcepub const fn doc(self, doc: &'static [&'static str]) -> ShapeBuilder
pub const fn doc(self, doc: &'static [&'static str]) -> ShapeBuilder
Set the documentation.
Sourcepub const fn attributes(self, attributes: &'static [Attr]) -> ShapeBuilder
pub const fn attributes(self, attributes: &'static [Attr]) -> ShapeBuilder
Set the attributes.
Sourcepub const fn type_tag(self, type_tag: &'static str) -> ShapeBuilder
pub const fn type_tag(self, type_tag: &'static str) -> ShapeBuilder
Set the type tag.
Sourcepub const fn inner(self, inner: &'static Shape) -> ShapeBuilder
pub const fn inner(self, inner: &'static Shape) -> ShapeBuilder
Set the inner shape (for transparent/newtype wrappers).
Sourcepub const fn builder_shape(self, builder: &'static Shape) -> ShapeBuilder
pub const fn builder_shape(self, builder: &'static Shape) -> ShapeBuilder
Set the builder shape for immutable collections.
If set, deserializers will build the value using the builder shape,
then convert to the target type. Used for immutable collections like
Bytes (builds through BytesMut) or Arc<[T]> (builds through Vec<T>).
Sourcepub const fn type_name(
self,
type_name: fn(&'static Shape, &mut Formatter<'_>, TypeNameOpts) -> Result<(), Error>,
) -> ShapeBuilder
pub const fn type_name( self, type_name: fn(&'static Shape, &mut Formatter<'_>, TypeNameOpts) -> Result<(), Error>, ) -> ShapeBuilder
Set the type name function for formatting generic type names.
For generic types like Vec<T>, this function formats the full name
including type parameters (e.g., Vec<String>).
Sourcepub const fn proxy(self, proxy: &'static ProxyDef) -> ShapeBuilder
pub const fn proxy(self, proxy: &'static ProxyDef) -> ShapeBuilder
Set the container-level proxy for custom serialization/deserialization.
When a proxy is set, the type will be serialized/deserialized through the proxy type instead of directly.
Sourcepub const fn format_proxies(
self,
proxies: &'static [FormatProxy],
) -> ShapeBuilder
pub const fn format_proxies( self, proxies: &'static [FormatProxy], ) -> ShapeBuilder
Set the format-specific container-level proxy definitions.
Format-specific proxies take precedence over the format-agnostic proxy when
the format matches. Use this for types that need different representations
in different formats (e.g., XML vs JSON).
Sourcepub const fn variance(self, variance: VarianceDesc) -> ShapeBuilder
pub const fn variance(self, variance: VarianceDesc) -> ShapeBuilder
Set the variance description for this type.
For types that propagate inner variance, use VarianceDesc::propagate(inner_shape).
For types with constant variance, use VarianceDesc::BIVARIANT or VarianceDesc::INVARIANT.
For complex types like function pointers, construct with VarianceDesc::new(base, deps).
Sourcepub const fn flags(self, flags: ShapeFlags) -> ShapeBuilder
pub const fn flags(self, flags: ShapeFlags) -> ShapeBuilder
Set the flags for this shape.
Sourcepub const fn untagged(self) -> ShapeBuilder
pub const fn untagged(self) -> ShapeBuilder
Mark this enum as untagged.
Untagged enums serialize their content directly without any discriminant.
Sourcepub const fn tag(self, tag: &'static str) -> ShapeBuilder
pub const fn tag(self, tag: &'static str) -> ShapeBuilder
Set the tag field name for internally/adjacently tagged enums.
Sourcepub const fn content(self, content: &'static str) -> ShapeBuilder
pub const fn content(self, content: &'static str) -> ShapeBuilder
Set the content field name for adjacently tagged enums.
Sourcepub const fn rename(self, rename: &'static str) -> ShapeBuilder
pub const fn rename(self, rename: &'static str) -> ShapeBuilder
Set the rename for this shape.
Sourcepub const fn is_numeric(self) -> ShapeBuilder
pub const fn is_numeric(self) -> ShapeBuilder
Mark this enum as numeric.
Numeric enums serialize to the underlying discriminant
Sourcepub const fn pod(self) -> ShapeBuilder
pub const fn pod(self) -> ShapeBuilder
Mark this type as Plain Old Data.
POD types have no invariants - any combination of valid field values produces a valid instance. This enables safe mutation through reflection.
Sourcepub const fn metadata_container(self) -> ShapeBuilder
pub const fn metadata_container(self) -> ShapeBuilder
Mark this struct as a metadata container.
Metadata containers serialize transparently through their non-metadata field while preserving metadata fields for formats that support them.
Sourcepub const fn build(self) -> Shape
pub const fn build(self) -> Shape
Build the Shape.
If ty was not explicitly set (still Type::Undefined), it will be
inferred from def.
§DeclId auto-computation
- Non-generic types: computed from
type_identifier - Generic types with
module_path: computed from@module_path#kind#type_identifier - Generic types without
module_path: panics (derive macro setsdecl_idexplicitly)