Skip to main content

Schema

Enum Schema 

Source
pub enum Schema {
    String {
        min: Option<f64>,
        max: Option<f64>,
        pattern: Option<Regex>,
    },
    Format {
        format: StringFormat,
        min: Option<f64>,
        max: Option<f64>,
        pattern: Option<Regex>,
    },
    Number {
        int: bool,
        min: Option<f64>,
        max: Option<f64>,
    },
    Boolean,
    Array {
        of: Box<Schema>,
        min: Option<f64>,
        max: Option<f64>,
    },
    Object {
        fields: Vec<(String, Schema)>,
        strict: bool,
    },
    Enum(Vec<String>),
    Const(ConstValue),
    Nullable(Box<Schema>),
    Default(Box<Schema>),
    Optional(Box<Schema>),
    Described {
        inner: Box<Schema>,
        description: String,
    },
}
Expand description

One compiled schema node. Bounds are f64 because JSON Schema bounds are numbers.

Variants§

§

String

type: string with optional minLength / maxLength (UTF-16 length) and pattern.

Fields

§min: Option<f64>

the shortest length

§max: Option<f64>

the longest length

§pattern: Option<Regex>

a regular expression the string must match

§

Format

type: string with format: <name>, a named zod string format. The format composes with minLength / maxLength / pattern, as the chained z.email().min(…).regex(…) does.

Fields

§format: StringFormat

the named format

§min: Option<f64>

the shortest length

§max: Option<f64>

the longest length

§pattern: Option<Regex>

a regular expression the string must match

§

Number

type: number, or type: integer (int: true), with optional minimum / maximum.

Fields

§int: bool

whether only integers are allowed

§min: Option<f64>

the smallest value

§max: Option<f64>

the largest value

§

Boolean

type: boolean

§

Array

type: array with an items schema (of) and optional minItems / maxItems.

Fields

§of: Box<Schema>

the schema for each element

§min: Option<f64>

the fewest elements

§max: Option<f64>

the most elements

§

Object

type: object: properties in declaration order; strict (additionalProperties: false) rejects unknown keys.

Fields

§fields: Vec<(String, Schema)>

the fields, in declaration order

§strict: bool

whether unknown keys are rejected

§

Enum(Vec<String>)

enum: [...]: a closed set of strings.

§

Const(ConstValue)

const: <scalar>: an exact literal.

§

Nullable(Box<Schema>)

type: [T, "null"]: also admit null.

§

Default(Box<Schema>)

default: <value>: a missing value passes (the default substitutes).

§

Optional(Box<Schema>)

A property not listed in required: a missing value passes.

§

Described

description:, carried for Finding.hint. Validation ignores it.

Fields

§inner: Box<Schema>

the wrapped schema

§description: String

the description text

Trait Implementations§

Source§

impl Clone for Schema

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Schema

Source§

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

Formats the value using the given formatter. 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> CloneToUninit for T
where T: Clone,

Source§

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

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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,

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.