Skip to main content

Constraint

Enum Constraint 

Source
#[non_exhaustive]
pub enum Constraint { Vocabulary { terms: Vec<Term>, closed: bool, }, Other { kind: String, spec: Value, }, }
Expand description

This crate’s own constraint type: what a schema document’s constraint loads as. One variant for the kind the format defines and one for every kind it does not.

The seam this crate is built around is that a constraint is the embedder’s type, and this does not close it: an embedder loads a Schema<Constraint> and maps it into a schema over its own type with Schema::map_constraints, reading the Other kinds it knows and keeping the rest as its own unchecked variant. What this type adds is that a reader with no embedder behind it — fig-schema check — can still load the document and say honestly what it did and did not check.

#[non_exhaustive]: the format may define another kind, so a match needs a _ arm.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Vocabulary

A controlled vocabulary, checked by validate_enum.

Fields

§terms: Vec<Term>

The terms, in declaration order.

§closed: bool

Whether a value outside the terms is rejected rather than warned about.

§

Other

A constraint of a kind this crate does not define — prov’s reference, or anything else an embedder reads. Validates every value to Reject(Issue::unchecked(..)): the fail-closed half of the format’s rule, spelled so that a reader which looks can tell unchecked from wrong.

Fields

§kind: String

The kind as written.

§spec: Value

The whole constraint mapping as read, kind included, for the embedder that knows what the rest of it means.

Implementations§

Source§

impl Constraint

Source

pub fn kind(&self) -> &str

The constraint’s kind as a schema document spells it: vocabulary, or whatever an Other carries.

Source

pub fn terms(&self) -> Option<&[Term]>

The terms, for a vocabulary — what a picker offers. None for a kind this crate cannot offer values from.

Trait Implementations§

Source§

impl Clone for Constraint

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Constraint

Source§

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

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

impl Display for Constraint

Source§

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

A one-line summary for a person: vocabulary, closed, 4 terms (1 retired), or reference — a kind this crate cannot check.

Source§

impl PartialEq for Constraint

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Constraint

Source§

impl Validate for Constraint

Source§

fn validate(&self, value: &Value) -> Validation

Check value against this constraint.

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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.