HashValidator

Struct HashValidator 

Source
pub struct HashValidator {
    pub comment: String,
    pub link: Option<Box<Validator>>,
    pub schema: Vec<Option<Hash>>,
    pub in_list: Vec<Hash>,
    pub nin_list: Vec<Hash>,
    pub query: bool,
    pub link_ok: bool,
    pub schema_ok: bool,
}
Expand description

Validator for hashes.

This validator type will only pass hash values. Validation passes if:

  • If the in list is not empty, the hash must be among the hashes in the list.
  • The hash must not be among the hashes in the nin list.
  • If link has a validator, the data in the Document referred to by the hash must pass that validator.
  • If the schema list is not empty, the Document referred to by the hash must use one of the schemas listed. A null value on the list means the schema containing this validator is also accepted.

The link and schema checks only apply when validating Entries, not Documents.

Hash validators are unique in that they do not always complete validation after examining a single value. If used for checking an Entry, they can require an additional Document for validation. For this reason, completing validation of an Entry requires completing a DataChecklist. See the Schema documentation for more details.

§Defaults

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

  • comment: “”
  • link: None
  • schema: empty
  • in_list: empty
  • nin_list: empty
  • query: false
  • link_ok: false
  • schema_ok: false

§Query Checking

Queries for hashes 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
  • link_ok: link
  • schema_ok: schema

In addition, if there is a validator for link, it is validated against the schema validator’s link validator.

Fields§

§comment: String

An optional comment explaining the validator.

§link: Option<Box<Validator>>

An optional validator used to validate the data in a Document linked to by the hash. If not present, any data is allowed in the linked Document.

§schema: Vec<Option<Hash>>

A list of allowed schemas for a Document linked to by the hash. A None value refers to the validator’s containing schema. For validators used in queries, None is skipped. If empty, this list is ignored during checking.

§in_list: Vec<Hash>

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

§nin_list: Vec<Hash>

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.

§link_ok: bool

If true, queries against matching spots may have a validator in link.

§schema_ok: bool

If true, queries against matching spots may have values in the schema list.

Implementations§

Source§

impl HashValidator

Source

pub fn new() -> Self

Make a new validator with the default configuration.

Set the link validator.

Source

pub fn schema_add(self, add: impl Into<Hash>) -> Self

Add a Hash to the schema list.

Source

pub fn schema_self(self) -> Self

Allow referred-to documents to use this validator’s containing schema.

Source

pub fn in_add(self, add: impl Into<Hash>) -> Self

Add a value to the in list.

Source

pub fn nin_add(self, add: impl Into<Hash>) -> Self

Add a value to the nin list.

Source

pub fn query(self, query: bool) -> Self

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

Set whether or not queries can use link.

Source

pub fn schema_ok(self, schema_ok: bool) -> Self

Set whether or not queries can use schema.

Source

pub fn build(self) -> Validator

Build this into a Validator enum.

Trait Implementations§

Source§

impl Clone for HashValidator

Source§

fn clone(&self) -> HashValidator

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for HashValidator

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for HashValidator

Source§

fn default() -> HashValidator

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

impl<'de> Deserialize<'de> for HashValidator

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for HashValidator

Source§

fn eq(&self, other: &HashValidator) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for HashValidator

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for HashValidator

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,