Struct fog_pack::validator::ArrayValidator[][src]

pub struct ArrayValidator {
Show 14 fields pub comment: String, pub contains: Vec<Validator>, pub items: Box<Validator>, pub prefix: Vec<Validator>, pub max_len: u32, pub min_len: u32, pub in_list: Vec<Vec<Value>>, pub nin_list: Vec<Vec<Value>>, pub unique: bool, pub query: bool, pub array: bool, pub contains_ok: bool, pub unique_ok: bool, pub size: bool,
}
Expand description

Validator for arrays.

This validator type will only pass array values. 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 arrays’s length is less than or equal to the value in max_len.
  • The arrays’s length is greater than or equal to the value in min_len.
  • If unique is true, the array items are all unique.
  • For each validator in the contains list, at least one item in the array passes.
  • Each item in the array is checked with a validator at the same index in the prefix array. All validators must pass. If there is no validator at the same index, the validator in items must pass. If a validator is not used, it passes automatially.

Defaults

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

  • comment: “”
  • contains: empty
  • items: Validator::Any
  • prefix: empty
  • max_len: u32::MAX
  • min_len: u32::MIN
  • in_list: empty
  • nin_list: empty
  • unique: false
  • query: false
  • array: false
  • contains_ok: false
  • unique_ok: false
  • size: false

Query Checking

Queries for arrays 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
  • array: prefix and items
  • contains_ok: contains
  • unique_ok: unique
  • size: max_len and min_len

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

  • Each validator in contains is checked against all of the schema’s prefix validators, as well as its items validator.
  • The items validator is checked against the schema’s `items’ validator
  • The prefix validators are checked against the schema’s prefix validators. Unmatched query validators are checked against the schema’s items validator.

Fields

comment: String

An optional comment explaining the validator.

contains: Vec<Validator>

For each validator in this array, at least one item in the array must pass the validator.

items: Box<Validator>

A validator that each item in the array must pass, unless it is instead checked by prefix.

prefix: Vec<Validator>

An array of validators, which are matched up against the items in the array. Unmatched validators automatically pass, while unmatched items are checked against the items Validator.

max_len: u32

The maximum allowed number of items in the array.

min_len: u32

The minimum allowed number of items in the array.

in_list: Vec<Vec<Value>>

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

nin_list: Vec<Vec<Value>>

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

unique: bool

If set, all items in the array must be unique.

query: bool

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

array: bool

If true, queries against matching spots may use items and prefix.

contains_ok: bool

If true, queries against matching spots may use contains.

unique_ok: bool

If true, queries against matching spots may use unique.

size: bool

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

Implementations

Make a new validator with the default configuration.

Set a comment for the validator.

Extend the contains list with another validator

Set the items validator.

Extend the prefix list with another 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 the items in the array must be unique.

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

Set whether or not queries can use the items and prefix values.

Set whether or not queries can use the contains value.

Set whether or not queries can use the unique setting.

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

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.