Skip to main content

Input

Trait Input 

Source
pub trait Input {
    type Child<'a>: Input
       where Self: 'a;

    // Required methods
    fn kind(&self) -> Kind;
    fn as_bool(&self) -> Option<bool>;
    fn as_int(&self) -> Option<Int>;
    fn as_f64(&self) -> Option<f64>;
    fn as_str(&self) -> Option<Cow<'_, str>>;
    fn len(&self) -> usize;
    fn item(&self, index: usize) -> Option<Self::Child<'_>>;
    fn slot(&self, key: &str) -> Slot<Self::Child<'_>>;
    fn each_key(&self, f: &mut dyn FnMut(&str));

    // Provided method
    fn is_empty(&self) -> bool { ... }
}
Expand description

A payload the validator can read in place.

Accessors return None when the value is not of that kind, so a caller never has to check twice. They are infallible on purpose: a binding that cannot read its own object has a bug, not a validation failure.

Required Associated Types§

Source

type Child<'a>: Input where Self: 'a

An element of an array, or the value at a key. Implementations should make this converge, usually to themselves or to a reference to themselves. A type whose child is a strictly new type on every level would make the validator recurse forever at compile time.

Required Methods§

Source

fn kind(&self) -> Kind

Source

fn as_bool(&self) -> Option<bool>

Source

fn as_int(&self) -> Option<Int>

Source

fn as_f64(&self) -> Option<f64>

Source

fn as_str(&self) -> Option<Cow<'_, str>>

Source

fn len(&self) -> usize

Elements for an array, keys for an object, zero otherwise.

Source

fn item(&self, index: usize) -> Option<Self::Child<'_>>

Source

fn slot(&self, key: &str) -> Slot<Self::Child<'_>>

Reads a key without collapsing absence into null.

Source

fn each_key(&self, f: &mut dyn FnMut(&str))

Visits every key of an object, for the unknown-field check.

Provided Methods§

Source

fn is_empty(&self) -> bool

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<T: Input> Input for &T

Source§

type Child<'a> = <T as Input>::Child<'a> where Self: 'a

Source§

fn kind(&self) -> Kind

Source§

fn as_bool(&self) -> Option<bool>

Source§

fn as_int(&self) -> Option<Int>

Source§

fn as_f64(&self) -> Option<f64>

Source§

fn as_str(&self) -> Option<Cow<'_, str>>

Source§

fn len(&self) -> usize

Source§

fn item(&self, index: usize) -> Option<Self::Child<'_>>

Source§

fn slot(&self, key: &str) -> Slot<Self::Child<'_>>

Source§

fn each_key(&self, f: &mut dyn FnMut(&str))

Implementors§

Source§

impl Input for Ref<'_, '_>

Source§

type Child<'x> = Ref<'_, '_> where Self: 'x

Source§

impl Input for Value

Source§

type Child<'a> = &'a Value