Nulls
The SchemaType::Null variant can be used to represent a literal null value. This works
best when paired with unions or fields that need to be nullable.
#![allow(unused)]
fn main() {
use schematic::{Schematic, Schema, SchemaBuilder, SchemaType};
impl Schematic for T {
fn build_schema(mut schema: SchemaBuilder) -> Schema {
schema.set_type_and_build(SchemaType::Null)
}
}
}
Automatically implemented for
()andOption<T>.
Marking as nullable
If you want a concrete schema to also accept null (an Optional value), you can use the
SchemaBuilder::nullable()
method. Under the hood, this will create a union of the defined type, and the null type.
#![allow(unused)]
fn main() {
// string | null
schema.nullable(schema.infer::<String>());
}