Skip to main content

BuildSchemaTrait

Trait BuildSchemaTrait 

Source
pub trait BuildSchemaTrait {
    // Required method
    fn build_schema(ctx: &mut SchemaBuilder) -> SchemaNodeContent;

    // Provided methods
    fn type_name() -> Option<&'static str> { ... }
    fn schema_metadata() -> SchemaMetadata { ... }
}
Expand description

Trait for types that can build their schema representation.

This trait is typically derived using #[derive(BuildSchema)], but can also be implemented manually for custom schema generation.

§Type Registration

Types can optionally provide a type_name() to register themselves in the schema’s $types namespace. This is useful for:

  • Creating reusable type definitions
  • Enabling type references across the schema
  • Providing meaningful names in generated schemas

Primitive types typically return None for type_name().

Required Methods§

Source

fn build_schema(ctx: &mut SchemaBuilder) -> SchemaNodeContent

Build the schema content for this type.

Use ctx.build::<T>() for nested types - this handles caching and recursion automatically.

Provided Methods§

Source

fn type_name() -> Option<&'static str>

The type name for registration in $types namespace.

Return Some("my-type") to register this type as $types.my-type. Return None (default) for inline/anonymous types.

Source

fn schema_metadata() -> SchemaMetadata

Optional metadata for this type’s schema node.

Override to provide description, deprecation status, defaults, or examples.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl BuildSchema for &str

Source§

impl BuildSchema for bool

Source§

impl BuildSchema for f32

Source§

impl BuildSchema for f64

Source§

impl BuildSchema for i8

Source§

impl BuildSchema for i16

Source§

impl BuildSchema for i32

Source§

impl BuildSchema for i64

Source§

impl BuildSchema for i128

Source§

impl BuildSchema for isize

Source§

impl BuildSchema for u8

Source§

impl BuildSchema for u16

Source§

impl BuildSchema for u32

Source§

impl BuildSchema for u64

Source§

impl BuildSchema for u128

Source§

impl BuildSchema for ()

Source§

impl BuildSchema for usize

Source§

impl BuildSchema for String

Source§

impl<A> BuildSchema for (A,)
where A: BuildSchema + 'static,

Source§

impl<A, B> BuildSchema for (A, B)
where A: BuildSchema + 'static, B: BuildSchema + 'static,

Source§

impl<A, B, C> BuildSchema for (A, B, C)
where A: BuildSchema + 'static, B: BuildSchema + 'static, C: BuildSchema + 'static,

Source§

impl<A, B, C, D> BuildSchema for (A, B, C, D)
where A: BuildSchema + 'static, B: BuildSchema + 'static, C: BuildSchema + 'static, D: BuildSchema + 'static,

Source§

impl<A, B, C, D, E> BuildSchema for (A, B, C, D, E)
where A: BuildSchema + 'static, B: BuildSchema + 'static, C: BuildSchema + 'static, D: BuildSchema + 'static, E: BuildSchema + 'static,

Source§

impl<A, B, C, D, E, F> BuildSchema for (A, B, C, D, E, F)
where A: BuildSchema + 'static, B: BuildSchema + 'static, C: BuildSchema + 'static, D: BuildSchema + 'static, E: BuildSchema + 'static, F: BuildSchema + 'static,

Source§

impl<K, V> BuildSchema for BTreeMap<K, V>
where K: BuildSchema + 'static, V: BuildSchema + 'static,

BTreeMap<K, V> is represented as a map

Source§

impl<K, V> BuildSchema for HashMap<K, V>
where K: BuildSchema + 'static, V: BuildSchema + 'static,

HashMap<K, V> is represented as a map

Source§

impl<T> BuildSchema for Option<T>
where T: BuildSchema + 'static,

Option is represented as a union: some(T) | none(null)

Source§

impl<T> BuildSchema for Box<T>
where T: BuildSchema + 'static,

Box delegates to T

Source§

impl<T> BuildSchema for Rc<T>
where T: BuildSchema + 'static,

Rc delegates to T

Source§

impl<T> BuildSchema for Arc<T>
where T: BuildSchema + 'static,

Arc delegates to T

Source§

impl<T> BuildSchema for Vec<T>
where T: BuildSchema + 'static,

Vec is represented as an array with item type T

Source§

impl<T, E> BuildSchema for Result<T, E>
where T: BuildSchema + 'static, E: BuildSchema + 'static,

Result<T, E> is represented as a union: ok(T) | err(E)

Implementors§