Struct fog_pack::validator::MapValidator [−][src]
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
inlist is not empty, the array must be among the arrays in the list. - The array must not be among the arrays in the
ninlist. - 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
KeyValidatorinkeys. - Each key is not among the strings in the
banlist. - 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:
- If the key is in
req, the corresponding validator is used to validate the value. - If the key is not in
reqbut is inopt, the corresponding validator is used to validate the value. - if the key is not in
reqoropt, the validator forvaluesis used to validate the value. - If there is no validator for
values, validation does not pass.
- If the key is in
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:
inandninlists - size:
max_lenandmin_len - map_ok:
req,opt,ban, andvalues - match_keys:
matchesinKeyValidator - len_keys:
max_lenandmin_leninKeyValidator
In addition, sub-validators in the query are matched against the schema’s sub-validators:
- The
valuesvalidator is checked against the schema’svaluesvalidator. - The
reqvalidators are checked against the schema’sreq/opt/valuesvalidators, choosing whichever validator is found first. If no validator is found, the check fails. - The
optvalidators are checked against the schema’sreq/opt/valuesvalidators, choosing whichever validator is found first. If no validator is found, the check fails.
Fields
comment: StringAn optional comment explaining the validator.
max_len: u32The maximum allowed number of key-value pairs in the map.
min_len: u32The minimum allowed number of key-value pairs in the map.
keys: KeyValidatorThe 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: boolIf true, queries against matching spots may have values in the in or nin lists.
size: boolIf true, queries against matching spots may use max_len and min_len.
map_ok: boolIf true, queries against matching spots may use req, opt, ban, and values.
match_keys: boolIf true, queries against matching spots may use matches in the Key Validator.
len_keys: boolIf true, queries against matching spots may use max_len and min_len in the Key Validator.
Implementations
impl MapValidator[src]
pub fn new() -> Self[src]
Make a new validator with the default configuration.
pub fn comment(self, comment: impl Into<String>) -> Self[src]
Set a comment for the validator.
pub fn values(self, values: Validator) -> Self[src]
Set the values validator.
pub fn req_add(self, key: impl Into<String>, req: Validator) -> Self[src]
Add a new validator to the req map.
pub fn opt_add(self, key: impl Into<String>, opt: Validator) -> Self[src]
Add a new validator to the opt map.
pub fn ban_add(self, ban: impl Into<String>) -> Self[src]
Add a new key to the ban list.
pub fn keys(self, keys: KeyValidator) -> Self[src]
Set the Key Validator.
pub fn max_len(self, max_len: u32) -> Self[src]
Set the maximum number of allowed bytes.
pub fn min_len(self, min_len: u32) -> Self[src]
Set the minimum number of allowed bytes.
pub fn in_add(self, add: impl Into<BTreeMap<String, Value>>) -> Self[src]
Add a value to the in list.
pub fn nin_add(self, add: impl Into<BTreeMap<String, Value>>) -> Self[src]
Add a value to the nin list.
pub fn query(self, query: bool) -> Self[src]
Set whether or not queries can use the in and nin lists.
pub fn size(self, size: bool) -> Self[src]
Set whether or not queries can use the max_len and min_len values.
pub fn map_ok(self, map_ok: bool) -> Self[src]
Set whether or not queries can use the req, opt, ban, and values values.
pub fn match_keys(self, match_keys: bool) -> Self[src]
Set whether or not queries can use the matches value for the Key Validator.
pub fn len_keys(self, len_keys: bool) -> Self[src]
Set whether or not queries can use the max_len and min_len values for the Key
Validator.
pub fn build(self) -> Validator[src]
Build this into a Validator enum.
Trait Implementations
impl Clone for MapValidator[src]
fn clone(&self) -> MapValidator[src]
pub fn clone_from(&mut self, source: &Self)1.0.0[src]
impl Debug for MapValidator[src]
impl Default for MapValidator[src]
impl<'de> Deserialize<'de> for MapValidator where
MapValidator: Default, [src]
MapValidator: Default,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>, [src]
__D: Deserializer<'de>,
impl PartialEq<MapValidator> for MapValidator[src]
fn eq(&self, other: &MapValidator) -> bool[src]
fn ne(&self, other: &MapValidator) -> bool[src]
impl Serialize for MapValidator[src]
fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
__S: Serializer, [src]
__S: Serializer,
impl StructuralPartialEq for MapValidator[src]
Auto Trait Implementations
impl RefUnwindSafe for MapValidator
impl Send for MapValidator
impl Sync for MapValidator
impl Unpin for MapValidator
impl UnwindSafe for MapValidator
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T[src]
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>, [src]
T: for<'de> Deserialize<'de>,
impl<T> From<T> for T[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone, [src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T[src]
pub fn clone_into(&self, target: &mut T)[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,