Skip to main content

Node

Struct Node 

Source
pub struct Node {
Show 38 fields pub kind: Kind, pub required: bool, pub required_set: bool, pub kind_set: bool, pub skippable: bool, pub silent: bool, pub empty: bool, pub nullable: bool, pub has_default: bool, pub default: Value, pub literal: Option<Value>, pub obj_children: IndexMap<String, Node>, pub obj_rest: Option<Box<Node>>, pub consumed: HashSet<String>, pub obj_keys: Vec<Arc<str>>, pub plain: bool, pub arr_children: Vec<Node>, pub arr_child: Option<Box<Node>>, pub arr_rest: Option<Box<Node>>, pub befores: Vec<Validator>, pub afters: Vec<Validator>, pub regexp: Option<Regex>, pub regexp_src: String, pub fault_msg: Option<String>, pub arg_fault: bool, pub list_mode: ListMode, pub list: Vec<Node>, pub disc: Option<Disc>, pub exact_vals: Vec<Value>, pub has_exact: bool, pub define_name: Option<String>, pub refer_name: Option<String>, pub refer_fill: bool, pub refer_strict: bool, pub rename_to: Option<String>, pub rename_keep: bool, pub rename_claim: Vec<String>, pub meta: IndexMap<String, Value>,
}
Expand description

A node of the compiled tree.

Fields§

§kind: Kind§required: bool§required_set: bool§kind_set: bool

The kind was named by the spec (a type token, type_), as against implied by a value: a key expression’s example keeps the named kind and supplies the default alone.

§skippable: bool

Optional and no default injection (p in TypeScript).

§silent: bool

Errors raised on or below this node are dropped (e: false).

§empty: bool

The empty string is allowed.

§nullable: bool

An explicit null is accepted as the value.

§has_default: bool§default: Value

Injected for a missing optional property.

§literal: Option<Value>

The declarative value the node was built from, when it was one.

§obj_children: IndexMap<String, Node>

Object children, in the order the spec declared them.

§obj_rest: Option<Box<Node>>

The shape of an unknown key (an open object); none for a closed one.

§consumed: HashSet<String>

The keys a closed object accepts: its declared keys, the targets of its renames and the sources they claim. Set when the tree is prepared.

§obj_keys: Vec<Arc<str>>

The declared keys in order, shared with the paths that name them. Set when the tree is prepared.

§plain: bool

Nothing but the structural check applies to a present value: no validator, rename, regexp or silence. Set when the tree is prepared, and lets a walk judge such a value in place.

§arr_children: Vec<Node>

The fixed positions of a tuple.

§arr_child: Option<Box<Node>>

The shape of every element after the fixed positions.

§arr_rest: Option<Box<Node>>

A Rest appended to an array.

§befores: Vec<Validator>§afters: Vec<Validator>§regexp: Option<Regex>

The pattern of a Regexp node.

§regexp_src: String

The pattern as written, in the shared subset: what renders and exports.

§fault_msg: Option<String>

A Fault message overriding the structural text.

§arg_fault: bool

Made by a builder given a wrong argument, as against a deliberate fault: the string form refuses such a node.

§list_mode: ListMode§list: Vec<Node>§disc: Option<Disc>

A Discriminated union: the tag it chooses by, and its branch names, which are the list in that order.

§exact_vals: Vec<Value>§has_exact: bool§define_name: Option<String>§refer_name: Option<String>§refer_fill: bool§refer_strict: bool§rename_to: Option<String>§rename_keep: bool§rename_claim: Vec<String>§meta: IndexMap<String, Value>

Free-form metadata from x$$ sidecar keys.

Implementations§

Source§

impl Node

Source

pub fn pick(self, names: impl Into<Names>) -> Node

Source

pub fn omit(self, names: impl Into<Names>) -> Node

Source

pub fn partial(self) -> Node

Source

pub fn extend(self, extra: impl Into<Spec>) -> Node

Source§

impl Node

Source

pub fn required(self) -> Node

Source

pub fn optional(self) -> Node

Source

pub fn default_to(self, dval: impl Into<Value>) -> Node

Optional with the default; named to leave Default::default alone. An untyped node is built over the default instead, and so takes the default’s kind, keeping the checks and flags it carried.

Source

pub fn skip(self) -> Node

Source

pub fn ignore(self) -> Node

Source

pub fn empty(self) -> Node

Source

pub fn nullable(self) -> Node

Source

pub fn open(self) -> Node

Source

pub fn closed(self) -> Node

Source

pub fn child(self, child: impl Into<Spec>) -> Node

Source

pub fn rest(self, child: impl Into<Spec>) -> Node

Source

pub fn fault(self, msg: impl Into<String>) -> Node

Source

pub fn never(self) -> Node

Source

pub fn any(self) -> Node

The value may be anything.

Source

pub fn type_(self, kind: impl Into<TypeRef>) -> Node

Adopt the reference type’s kind and its required, skippable and default state. Structural children are deliberately not copied: type_(Object) is a closed object and type_(Array) accepts any elements.

Source

pub fn string(self) -> Node

Source

pub fn number(self) -> Node

Source

pub fn boolean(self) -> Node

Source

pub fn object(self) -> Node

Source

pub fn array(self) -> Node

Source

pub fn function(self) -> Node

Source

pub fn integer(self) -> Node

Source

pub fn date(self) -> Node

Source

pub fn func(self) -> Node

A function-typed value; the required state is kept.

Source

pub fn exact<I>(self, vals: I) -> Node
where I: IntoIterator, I::Item: Into<Value>,

Source

pub fn min(self, bound: impl Into<Value>) -> Node

Source

pub fn max(self, bound: impl Into<Value>) -> Node

Source

pub fn above(self, bound: impl Into<Value>) -> Node

Source

pub fn below(self, bound: impl Into<Value>) -> Node

Source

pub fn len(self, length: impl Into<Value>) -> Node

Source

pub fn check<F>(self, f: F) -> Node
where F: Fn(&mut State<'_>, &mut Update) -> bool + Send + Sync + 'static,

Source

pub fn check_re(self, re: Regex) -> Node

Source

pub fn before<F>(self, f: F) -> Node
where F: Fn(&mut State<'_>, &mut Update) -> bool + Send + Sync + 'static,

Source

pub fn after<F>(self, f: F) -> Node
where F: Fn(&mut State<'_>, &mut Update) -> bool + Send + Sync + 'static,

Source

pub fn define(self, name: impl Into<String>) -> Node

Source

pub fn refer(self, name: impl Into<String>) -> Node

Source

pub fn refer_with(self, name: impl Into<String>, opts: ReferOptions) -> Node

Source

pub fn rename(self, name: impl Into<String>) -> Node

Source

pub fn rename_with(self, name: impl Into<String>, opts: RenameOptions) -> Node

Source

pub fn catch(self, fallback: impl Into<Value>) -> Node

Source

pub fn transform<F>(self, f: F) -> Node
where F: Fn(Value, &mut State<'_>) -> Value + Send + Sync + 'static,

Source

pub fn describe(self, description: impl Into<String>) -> Node

Source

pub fn coerce(self) -> Node

Source

pub fn email(self) -> Node

Source

pub fn url(self) -> Node

Source

pub fn uuid(self) -> Node

Source

pub fn date_time(self) -> Node

Source

pub fn ip(self) -> Node

Source

pub fn ipv4(self) -> Node

Source

pub fn ipv6(self) -> Node

Source§

impl Node

Source

pub fn of(kind: Kind) -> Node

Source

pub fn is_open(&self) -> bool

Whether the object accepts keys it does not declare.

Source

pub fn is_ignore(&self) -> bool

An Ignore node: optional, no default injection, and silent.

Source

pub fn zero_for(kind: Kind) -> Value

The empty value of a kind (EMPTY_VAL in TypeScript).

Trait Implementations§

Source§

impl Clone for Node

Source§

fn clone(&self) -> Node

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 Node

Source§

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

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

impl Default for Node

Source§

fn default() -> Node

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

impl From<Node> for TypeRef

Source§

fn from(n: Node) -> Self

Converts to this type from the input type.
Source§

impl From<Node> for Spec

Source§

fn from(n: Node) -> Self

Converts to this type from the input type.
Source§

impl From<Token> for Node

Source§

fn from(t: Token) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Node

§

impl !UnwindSafe for Node

§

impl Freeze for Node

§

impl Send for Node

§

impl Sync for Node

§

impl Unpin for Node

§

impl UnsafeUnpin for Node

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, 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.