Struct SchemaBuilder

Source
pub struct SchemaBuilder { /* private fields */ }
Expand description

A Schema builder.

Implementations§

Source§

impl SchemaBuilder

Source

pub fn generate<T: Schematic>() -> Schema

Generate a schema from the provided type.

Source

pub fn build_root<T: Schematic>() -> Schema

Generate a schema from the provided type.

Source

pub fn build(&mut self) -> Schema

Build the schema from the configured values.

Source

pub fn set_deprecated(&mut self, value: impl AsRef<str>)

Mark this schema as deprecated.

Source

pub fn set_description(&mut self, value: impl AsRef<str>)

Add a description for this schema.

Source

pub fn set_name(&mut self, value: impl AsRef<str>)

Add a name for this schema.

Source

pub fn set_type(&mut self, value: SchemaType)

Set the type of schema.

Source

pub fn set_type_and_build(&mut self, value: SchemaType) -> Schema

Set the type of schema and then build it.

Source

pub fn array(&mut self, value: ArrayType) -> Schema

Build an array type.

Source

pub fn boolean(&mut self, value: BooleanType) -> Schema

Build a boolean type.

Source

pub fn boolean_default(&mut self) -> Schema

Build a boolean type with default settings.

Source

pub fn enumerable(&mut self, value: EnumType) -> Schema

Build an enum type.

Source

pub fn float(&mut self, value: FloatType) -> Schema

Build a float type.

Source

pub fn float32_default(&mut self) -> Schema

Build a 32bit float type with default settings.

Source

pub fn float64_default(&mut self) -> Schema

Build a 64bit float type with default settings.

Source

pub fn integer(&mut self, value: IntegerType) -> Schema

Build an integer type.

Source

pub fn literal(&mut self, value: LiteralType) -> Schema

Build a literal type.

Source

pub fn literal_value(&mut self, value: LiteralValue) -> Schema

Build a literal type with a value.

Source

pub fn nest(&self) -> SchemaBuilder

Build a nested Schema by cloning another builder.

Source

pub fn nullable(&mut self, value: impl Into<Schema>) -> Schema

Build a schema that is also nullable (uses a union).

Source

pub fn object(&mut self, value: ObjectType) -> Schema

Build an object type.

Source

pub fn string(&mut self, value: StringType) -> Schema

Build a string type.

Source

pub fn string_default(&mut self) -> Schema

Build a string type with default settings.

Source

pub fn structure(&mut self, value: StructType) -> Schema

Build a struct type.

Source

pub fn tuple(&mut self, value: TupleType) -> Schema

Build a tuple type.

Source

pub fn union(&mut self, value: UnionType) -> Schema

Build a union type.

Source

pub fn infer<T: Schematic>(&self) -> Schema

Infer a Schema from a type that implements Schematic.

Source

pub fn infer_as_nested<T: Schematic>(&self) -> Schema

Infer a Schema from a type that implements Schematic, and mark the schema is partial (is marked as nested).

Source

pub fn infer_with_default<T: Schematic>(&self, default: LiteralValue) -> Schema

Infer a Schema from a type that implements Schematic, and also provide a default literal value.

Methods from Deref<Target = SchemaType>§

Source

pub fn get_default(&self) -> Option<&LiteralValue>

Return a default value from the inner schema type.

Source

pub fn is_null(&self) -> bool

Return true if the schema is an explicit null.

Source

pub fn is_nullable(&self) -> bool

Return true if the schema is nullable (a union with a null).

Source

pub fn is_reference(&self) -> bool

Return true if the schema is a reference.

Source

pub fn is_struct(&self) -> bool

Return true if the schema is a struct.

Source

pub fn set_default(&mut self, default: LiteralValue)

Set the default of the inner schema type.

Source

pub fn add_field(&mut self, key: &str, value: impl Into<SchemaField>)

Add a field to the type if it’s a struct.

Trait Implementations§

Source§

impl Clone for SchemaBuilder

Source§

fn clone(&self) -> SchemaBuilder

Returns a copy 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 SchemaBuilder

Source§

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

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

impl Default for SchemaBuilder

Source§

fn default() -> SchemaBuilder

Returns the “default value” for a type. Read more
Source§

impl Deref for SchemaBuilder

Source§

type Target = SchemaType

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl DerefMut for SchemaBuilder

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl From<SchemaBuilder> for Schema

Source§

fn from(builder: SchemaBuilder) -> Self

Converts to this type from the input type.

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> CloneToUninit for T
where T: Clone,

Source§

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

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.