Struct fog_pack::validator::EnumValidator [−][src]
“Enum” validator that selects a validator based on the value’s enum variant.
This validator expects a serialized Rust enum. A serialized enum consists of either a single
string (a unit variant) or a map with a single key-value pair, where the key is the name of the
enum variant and the value is the associated data. The associated data is validated against the
matching validator in the contained BTreeMap. If there is no match, validation fails.
For unit variants, there is no validator, and they pass as long as their name is a key in the
BTreeMap.
Query Checking
The query validator must be an Any or an Enum validator, and the maps are directly checked against
each other. The query validator may use a subset of the enum list. For unit variants, both the
query validator and schema validator must have None instead of a validator. As an example,
see the following:
// Say we have a enum like this: enum ExampleEnum { Empty, Integer(Integer), String(String), } // Let's use this as our schema-side validator let entry_validator = EnumValidator::new() .insert("Empty", None) .insert("Integer", Some(IntValidator::new().build())) .insert("String", Some(StrValidator::new().build())) .build(); // We'll build a full schema, so we can do query validation let schema_doc = SchemaBuilder::new(Validator::Null) .entry_add("item", entry_validator, None) .build() .unwrap(); let schema = Schema::from_doc(&schema_doc).unwrap(); // This query is accepted because all enum validators match. Note how // String isn't present, because the query doesn't need to have all // possible enums. let query_validator = EnumValidator::new() .insert("Empty", None) .insert("Integer", Some(IntValidator::new().build())) .build(); let query = NewQuery::new("item", query_validator); assert!(schema.encode_query(query).is_ok()); // This query, however, has a validator for "Empty", so it doesn't work: let query_validator = EnumValidator::new() .insert("Empty", Some(Validator::Null)) .insert("Integer", Some(IntValidator::new().build())) .build(); let query = NewQuery::new("item", query_validator); assert!(schema.encode_query(query).is_err());
Implementations
impl EnumValidator[src]
pub fn new() -> Self[src]
Make a new validator with the default configuration.
pub fn insert(
self,
variant: impl Into<String>,
validator: Option<Validator>
) -> Self[src]
self,
variant: impl Into<String>,
validator: Option<Validator>
) -> Self
Add a new enum to the set.
pub fn build(self) -> Validator[src]
Build this into a Validator enum.
pub fn iter(&self) -> Iter<'_, String, Option<Validator>>[src]
pub fn values(&self) -> Values<'_, String, Option<Validator>>[src]
Trait Implementations
impl Clone for EnumValidator[src]
fn clone(&self) -> EnumValidator[src]
pub fn clone_from(&mut self, source: &Self)1.0.0[src]
impl Debug for EnumValidator[src]
impl Default for EnumValidator[src]
impl<'de> Deserialize<'de> for EnumValidator[src]
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>, [src]
__D: Deserializer<'de>,
impl PartialEq<EnumValidator> for EnumValidator[src]
fn eq(&self, other: &EnumValidator) -> bool[src]
fn ne(&self, other: &EnumValidator) -> bool[src]
impl Serialize for EnumValidator[src]
fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
__S: Serializer, [src]
__S: Serializer,
impl StructuralPartialEq for EnumValidator[src]
Auto Trait Implementations
impl RefUnwindSafe for EnumValidator
impl Send for EnumValidator
impl Sync for EnumValidator
impl Unpin for EnumValidator
impl UnwindSafe for EnumValidator
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>,