Struct fog_pack::validator::MapValidator[][src]

pub struct MapValidator {
Show 15 fields pub comment: String, pub max_len: u32, pub min_len: u32, pub keys: KeyValidator, pub values: Option<Box<Validator>>, pub req: BTreeMap<String, Validator>, pub opt: BTreeMap<String, Validator>, pub ban: Vec<String>, pub in_list: Vec<BTreeMap<String, Value>>, pub nin_list: Vec<BTreeMap<String, Value>>, pub query: bool, pub size: bool, pub map_ok: bool, pub match_keys: bool, pub len_keys: bool,
}
Expand description

Validator for maps.

This validator will only pass maps, whose keys are strings and values are any valid fog-pack value. Validation passes if:

  • If the in list is not empty, the array must be among the arrays in the list.
  • The array must not be among the arrays in the nin list.
  • The number of key-value pairs in the map is less than or equal to the value in max_len.
  • The number of key-value pairs in the map is greater than or equal to the value in min_len.
  • Each key passes the KeyValidator in keys.
  • Each key is not among the strings in the ban list.
  • There must be a matching key-value in the map for each key-validator pair in req .
  • For each key-value pair in the map:
    1. If the key is in req, the corresponding validator is used to validate the value.
    2. If the key is not in req but is in opt, the corresponding validator is used to validate the value.
    3. if the key is not in req or opt, the validator for values is used to validate the value.
    4. If there is no validator for values, validation does not pass.

Note how each key-value pair must be validated, so an unlimited collection of key-value pairs isn’t allowed unless there is a validator present in values.

Defaults

Fields that aren’t specified for the validator use their defaults instead. The defaults for each field are:

  • comment: “”
  • max_len: u32::MAX
  • min_len: u32::MIN
  • keys: KeyValidator::default()
  • values: None
  • req: empty
  • opt: empty
  • ban: empty
  • in_list: empty
  • nin_list: empty
  • query: false
  • size: false
  • map_ok: false
  • match_keys: false
  • len_keys: false

Query Checking

Queries for maps are only allowed to use non-default values for each field if the corresponding query permission is set in the schema’s validator:

  • query: in and nin lists
  • size: max_len and min_len
  • map_ok: req, opt, ban, and values
  • match_keys: matches in KeyValidator
  • len_keys: max_len and min_len in KeyValidator

In addition, sub-validators in the query are matched against the schema’s sub-validators:

  • The values validator is checked against the schema’s values validator.
  • The req validators are checked against the schema’s req/opt/values validators, choosing whichever validator is found first. If no validator is found, the check fails.
  • The opt validators are checked against the schema’s req/opt/values validators, choosing whichever validator is found first. If no validator is found, the check fails.

Fields

comment: String

An optional comment explaining the validator.

max_len: u32

The maximum allowed number of key-value pairs in the map.

min_len: u32

The minimum allowed number of key-value pairs in the map.

keys: KeyValidator

The sub-validator for keys in the map.

values: Option<Box<Validator>>

An optional validator that each value in the map must pass, unless it is instead checked by a validator in req or opt. Unchecked values cause the map to fail validation.

req: BTreeMap<String, Validator>

A map whose keys must all be present in a passing map, and whose validators are used to check the value held by a matching key in the map.

opt: BTreeMap<String, Validator>

A map whose keys may be present in a map, and whose validators are used to check the value held by a matching key in the map, unless it is first checked by a validator in req.

ban: Vec<String>

A list of keys that may not be present in the map.

in_list: Vec<BTreeMap<String, Value>>

A vector of specific allowed values, stored under the in field. If empty, this vector is not checked against.

nin_list: Vec<BTreeMap<String, Value>>

A vector of specific unallowed values, stored under the nin field.

query: bool

If true, queries against matching spots may have values in the in or nin lists.

size: bool

If true, queries against matching spots may use max_len and min_len.

map_ok: bool

If true, queries against matching spots may use req, opt, ban, and values.

match_keys: bool

If true, queries against matching spots may use matches in the Key Validator.

len_keys: bool

If true, queries against matching spots may use max_len and min_len in the Key Validator.

Implementations

Make a new validator with the default configuration.

Set a comment for the validator.

Set the values validator.

Add a new validator to the req map.

Add a new validator to the opt map.

Add a new key to the ban list.

Set the Key Validator.

Set the maximum number of allowed bytes.

Set the minimum number of allowed bytes.

Add a value to the in list.

Add a value to the nin list.

Set whether or not queries can use the in and nin lists.

Set whether or not queries can use the max_len and min_len values.

Set whether or not queries can use the req, opt, ban, and values values.

Set whether or not queries can use the matches value for the Key Validator.

Set whether or not queries can use the max_len and min_len values for the Key Validator.

Build this into a Validator enum.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Deserialize this value from the given Serde deserializer. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

Should always be Self

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.