Trait jaq_interpret::ValT

source ·
pub trait ValT: Clone + Display + From<bool> + From<isize> + From<String> + FromIterator<Self> + PartialEq + PartialOrd + Add<Output = Result<Self, Error<Self>>> + Sub<Output = Result<Self, Error<Self>>> + Mul<Output = Result<Self, Error<Self>>> + Div<Output = Result<Self, Error<Self>>> + Rem<Output = Result<Self, Error<Self>>> + Neg<Output = Result<Self, Error<Self>>> {
    // Required methods
    fn from_num(n: &str) -> Result<Self, Error<Self>>;
    fn from_map<I: IntoIterator<Item = (Self, Self)>>(
        iter: I
    ) -> Result<Self, Error<Self>>;
    fn values(self) -> Box<dyn Iterator<Item = Result<Self, Error<Self>>>>;
    fn index(self, index: &Self) -> Result<Self, Error<Self>>;
    fn range(self, range: Range<Option<&Self>>) -> Result<Self, Error<Self>>;
    fn map_values<I: Iterator<Item = Result<Self, Error<Self>>>>(
        self,
        opt: Opt,
        f: impl Fn(Self) -> I
    ) -> Result<Self, Error<Self>>;
    fn map_index<I: Iterator<Item = Result<Self, Error<Self>>>>(
        self,
        index: &Self,
        opt: Opt,
        f: impl Fn(Self) -> I
    ) -> Result<Self, Error<Self>>;
    fn map_range<I: Iterator<Item = Result<Self, Error<Self>>>>(
        self,
        range: Range<Option<&Self>>,
        opt: Opt,
        f: impl Fn(Self) -> I
    ) -> Result<Self, Error<Self>>;
    fn as_bool(&self) -> bool;
    fn as_str(&self) -> Option<&str>;
}
Expand description

Values that can be processed by the interpreter.

Implement this trait if you want jaq to process your own type of values.

Required Methods§

source

fn from_num(n: &str) -> Result<Self, Error<Self>>

Create a number from a string.

The number should adhere to the format accepted by f64::from_str.

source

fn from_map<I: IntoIterator<Item = (Self, Self)>>( iter: I ) -> Result<Self, Error<Self>>

Create an associative map (or object) from a sequence of key-value pairs.

This is used when creating values with the syntax {k: v}.

source

fn values(self) -> Box<dyn Iterator<Item = Result<Self, Error<Self>>>>

Yield the children of a value.

This is used by .[].

source

fn index(self, index: &Self) -> Result<Self, Error<Self>>

Yield the child of a value at the given index.

This is used by .[k].

If v.index(k) is Ok(_), then it is contained in v.values().

source

fn range(self, range: Range<Option<&Self>>) -> Result<Self, Error<Self>>

Yield a slice of the value with the given range.

This is used by .[s:e], .[s:], and .[:e].

source

fn map_values<I: Iterator<Item = Result<Self, Error<Self>>>>( self, opt: Opt, f: impl Fn(Self) -> I ) -> Result<Self, Error<Self>>

Map a function over the children of the value.

This is used by

If the children of the value are undefined, then:

source

fn map_index<I: Iterator<Item = Result<Self, Error<Self>>>>( self, index: &Self, opt: Opt, f: impl Fn(Self) -> I ) -> Result<Self, Error<Self>>

Map a function over the child of the value at the given index.

This is used by .[k] |= f.

See Self::map_values for the behaviour of opt.

source

fn map_range<I: Iterator<Item = Result<Self, Error<Self>>>>( self, range: Range<Option<&Self>>, opt: Opt, f: impl Fn(Self) -> I ) -> Result<Self, Error<Self>>

Map a function over the slice of the value with the given range.

This is used by .[s:e] |= f, .[s:] |= f, and .[:e] |= f.

See Self::map_values for the behaviour of opt.

source

fn as_bool(&self) -> bool

Return a boolean representation of the value.

This is used by if v then ....

source

fn as_str(&self) -> Option<&str>

If the value is a string, return it.

If v.as_str() yields Some(s), then "\(v)" yields s, otherwise it yields v.to_string() (provided by Display).

Object Safety§

This trait is not object safe.

Implementors§

source§

impl ValT for Val