Enum schematic_types::SchemaType
source · 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
impl SchemaType
sourcepub fn infer<T: Schematic>() -> SchemaType
pub fn infer<T: Schematic>() -> SchemaType
Infer a schema from a type that implements Schematic.
sourcepub fn infer_with_default<T: Schematic>(default: LiteralValue) -> SchemaType
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.
sourcepub fn infer_partial<T: Schematic>() -> SchemaType
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).
sourcepub fn array(items_type: SchemaType) -> SchemaType
pub fn array(items_type: SchemaType) -> SchemaType
Create an array schema with the provided item types.
sourcepub fn boolean() -> SchemaType
pub fn boolean() -> SchemaType
Create a boolean type.
sourcepub fn enumerable<I>(values: I) -> SchemaTypewhere
I: IntoIterator<Item = LiteralValue>,
pub fn enumerable<I>(values: I) -> SchemaTypewhere
I: IntoIterator<Item = LiteralValue>,
Create an enumerable type with the provided literal values.
sourcepub fn float(kind: FloatKind) -> SchemaType
pub fn float(kind: FloatKind) -> SchemaType
Create a float schema with the provided kind.
sourcepub fn integer(kind: IntegerKind) -> SchemaType
pub fn integer(kind: IntegerKind) -> SchemaType
Create an integer schema with the provided kind.
sourcepub fn literal(value: LiteralValue) -> SchemaType
pub fn literal(value: LiteralValue) -> SchemaType
Create a literal schema with the provided value.
sourcepub fn nullable(schema: SchemaType) -> SchemaType
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.
sourcepub fn object(key_type: SchemaType, value_type: SchemaType) -> SchemaType
pub fn object(key_type: SchemaType, value_type: SchemaType) -> SchemaType
Create an indexed/mapable object schema with the provided key and value types.
sourcepub fn string() -> SchemaType
pub fn string() -> SchemaType
Create a string schema.
sourcepub fn structure<I>(fields: I) -> SchemaTypewhere
I: IntoIterator<Item = SchemaField>,
pub fn structure<I>(fields: I) -> SchemaTypewhere
I: IntoIterator<Item = SchemaField>,
Create a struct/shape schema with the provided fields.
sourcepub fn tuple<I>(items_types: I) -> SchemaTypewhere
I: IntoIterator<Item = SchemaType>,
pub fn tuple<I>(items_types: I) -> SchemaTypewhere
I: IntoIterator<Item = SchemaType>,
Create a tuple schema with the provided item types.
sourcepub fn union<I>(variants_types: I) -> SchemaTypewhere
I: IntoIterator<Item = SchemaType>,
pub fn union<I>(variants_types: I) -> SchemaTypewhere
I: IntoIterator<Item = SchemaType>,
Create an “any of” union.
sourcepub fn union_one<I>(variants_types: I) -> SchemaTypewhere
I: IntoIterator<Item = SchemaType>,
pub fn union_one<I>(variants_types: I) -> SchemaTypewhere
I: IntoIterator<Item = SchemaType>,
Create a “one of” union.
sourcepub fn get_default(&self) -> Option<&LiteralValue>
pub fn get_default(&self) -> Option<&LiteralValue>
Return a default value from the inner schema type.
sourcepub fn is_nullable(&self) -> bool
pub fn is_nullable(&self) -> bool
Return true if the schema is nullable (a union with a null).
sourcepub fn set_default(&mut self, default: LiteralValue)
pub fn set_default(&mut self, default: LiteralValue)
Set the default of the inner schema type.
sourcepub fn set_name<S: AsRef<str>>(&mut self, name: S)
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.
sourcepub fn set_partial(&mut self, state: bool)
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.
sourcepub fn add_field(&mut self, field: SchemaField)
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
impl Clone for SchemaType
source§fn clone(&self) -> SchemaType
fn clone(&self) -> SchemaType
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more