Enum toml_schema::TomlSchema
source · 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
Integer
Date
Bool
Float
Table
Fields
extras: Vec<TableEntry>
Array
Anything
Exact(Value)
Implementations§
source§impl TomlSchema
impl TomlSchema
sourcepub fn from_table(table: &Table) -> Result<(TomlSchema, Option<Value>), String>
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 valueErr(..)
=> 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
impl TomlSchema
sourcepub fn check<'s, 'v>(
&'s self,
data: &'v Value
) -> Result<(), SchemaError<'s, 'v>>
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
sourcepub fn check_and_complete<'s, 'v>(
&'s self,
data: &'v mut Value
) -> Result<(), SchemaError<'s, 'v>>
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
impl Clone for TomlSchema
source§fn clone(&self) -> TomlSchema
fn clone(&self) -> TomlSchema
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more