pub enum SchemaType {
Show 13 variants Null, Unknown, Array(ArrayType), Boolean(BooleanType), Enum(EnumType), Float(FloatType), Integer(IntegerType), Literal(LiteralType), Object(ObjectType), Struct(StructType), String(StringType), Tuple(TupleType), Union(UnionType),
}
Expand description

All possible types within a schema.

Variants§

§

Null

§

Unknown

§

Array(ArrayType)

§

Boolean(BooleanType)

§

Enum(EnumType)

§

Float(FloatType)

§

Integer(IntegerType)

§

Literal(LiteralType)

§

Object(ObjectType)

§

Struct(StructType)

§

String(StringType)

§

Tuple(TupleType)

§

Union(UnionType)

Implementations§

source§

impl SchemaType

source

pub fn infer<T: Schematic>() -> SchemaType

Infer a schema from a type that implements Schematic.

source

pub fn infer_with_default<T: Schematic>(default: LiteralValue) -> SchemaType

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

source

pub fn infer_partial<T: Schematic>() -> SchemaType

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

source

pub fn array(items_type: SchemaType) -> SchemaType

Create an array schema with the provided item types.

source

pub fn boolean() -> SchemaType

Create a boolean type.

source

pub fn enumerable<I>(values: I) -> SchemaType
where I: IntoIterator<Item = LiteralValue>,

Create an enumerable type with the provided literal values.

source

pub fn float(kind: FloatKind) -> SchemaType

Create a float schema with the provided kind.

source

pub fn integer(kind: IntegerKind) -> SchemaType

Create an integer schema with the provided kind.

source

pub fn literal(value: LiteralValue) -> SchemaType

Create a literal schema with the provided value.

source

pub fn nullable(schema: SchemaType) -> SchemaType

Convert the provided schema to a nullable type. If already nullable, do nothing and return, otherwise convert to a union.

source

pub fn object(key_type: SchemaType, value_type: SchemaType) -> SchemaType

Create an indexed/mapable object schema with the provided key and value types.

source

pub fn string() -> SchemaType

Create a string schema.

source

pub fn structure<I>(fields: I) -> SchemaType
where I: IntoIterator<Item = SchemaField>,

Create a struct/shape schema with the provided fields.

source

pub fn tuple<I>(items_types: I) -> SchemaType
where I: IntoIterator<Item = SchemaType>,

Create a tuple schema with the provided item types.

source

pub fn union<I>(variants_types: I) -> SchemaType
where I: IntoIterator<Item = SchemaType>,

Create an “any of” union.

source

pub fn union_one<I>(variants_types: I) -> SchemaType
where I: IntoIterator<Item = SchemaType>,

Create a “one of” union.

source

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

Return a default value from the inner schema type.

source

pub fn get_name(&self) -> Option<&String>

Return a name 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_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 set_name<S: AsRef<str>>(&mut self, name: S)

Set the name of the inner schema type. If the inner type does not support names, this is a no-op.

source

pub fn set_partial(&mut self, state: bool)

Mark the inner schema type as partial. Only structs and unions can be marked partial, but arrays and objects will also be recursively set to update the inner type.

source

pub fn add_field(&mut self, field: SchemaField)

Add the field to the inner schema type. This is only applicable to enums, structs, and unions, otherwise this is a no-op.

Trait Implementations§

source§

impl Clone for SchemaType

source§

fn clone(&self) -> SchemaType

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 SchemaType

source§

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

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

impl Default for SchemaType

source§

fn default() -> SchemaType

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

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

§

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

§

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

§

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.