pub enum TomlSchema {
    Alternative(Vec<TomlSchema>),
    String {
        regex: Regex,
    },
    Integer {
        min: i64,
        max: i64,
    },
    Date,
    Bool,
    Float {
        min: f64,
        max: f64,
        nan_ok: bool,
    },
    Table {
        extras: Vec<TableEntry>,
        min: usize,
        max: usize,
        entries: HashMap<String, (TomlSchema, Option<Value>)>,
    },
    Array {
        cond: Box<TomlSchema>,
        min: usize,
        max: usize,
    },
    Anything,
    Exact(Value),
}
Expand description

The main type of the crate, it can be constructed from a toml::Table object or by hand, the main constructor for this type is TomlSchema::try_from

Variants§

§

Alternative(Vec<TomlSchema>)

§

String

Fields

§regex: Regex
§

Integer

Fields

§min: i64
§max: i64
§

Date

§

Bool

§

Float

Fields

§min: f64
§max: f64
§nan_ok: bool
§

Table

Fields

§extras: Vec<TableEntry>
§min: usize
§max: usize
§

Array

Fields

§min: usize
§max: usize
§

Anything

§

Exact(Value)

Implementations§

source§

impl TomlSchema

source

pub fn from_table(table: &Table) -> Result<(TomlSchema, Option<Value>), String>

The internal constructor for a schema, from toml data, the returned values are

  • Ok(..) => the schema and it’s default value
  • Err(..) => Some kind of indication on where parsing the schema falied

note: no checking is done on the default values, that means the schema may contain default values that dont match it and fail on valid data using check_and_complete(..)

source§

impl TomlSchema

source

pub fn check<'s, 'v>( &'s self, data: &'v Value ) -> Result<(), SchemaError<'s, 'v>>

This checks that a toml value matches a schema, without modifying/copying, the returned error cannot outlive the passed toml value or self since it contains references to them

source

pub fn check_and_complete<'s, 'v>( &'s self, data: &'v mut Value ) -> Result<(), SchemaError<'s, 'v>>

Check that the data matches the schema and fills in the default values as needed

important note: default values are checked against the schema and validation will fail if a default value does not match the schema, this means that TomlSchema::check_and_complete can fail even when TomlSchema::check passes

Trait Implementations§

source§

impl Clone for TomlSchema

source§

fn clone(&self) -> TomlSchema

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 TomlSchema

source§

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

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

impl From<&TomlSchema> for SchemaType

source§

fn from(value: &TomlSchema) -> Self

Converts to this type from the input type.
source§

impl TryFrom<Map<String, Value>> for TomlSchema

source§

fn try_from(table: Table) -> Result<Self, String>

The main constructor for a TomlSchema, calls TomlSchema::from_table and discards the default value

note: default values are not checked against the schema

§

type Error = String

The type returned in the event of a conversion error.

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.