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§
sourcefn from_num(n: &str) -> Result<Self, Error<Self>>
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.
sourcefn from_map<I: IntoIterator<Item = (Self, Self)>>(
iter: I
) -> Result<Self, Error<Self>>
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}.
sourcefn values(self) -> Box<dyn Iterator<Item = Result<Self, Error<Self>>>>
fn values(self) -> Box<dyn Iterator<Item = Result<Self, Error<Self>>>>
Yield the children of a value.
This is used by .[].
sourcefn index(self, index: &Self) -> Result<Self, Error<Self>>
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().
sourcefn range(self, range: Range<Option<&Self>>) -> Result<Self, Error<Self>>
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].
sourcefn map_values<I: Iterator<Item = Result<Self, Error<Self>>>>(
self,
opt: Opt,
f: impl Fn(Self) -> I
) -> 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>>
Map a function over the children of the value.
This is used by
.[] |= f(opt=Opt::Essential) and.[]? |= f(opt=Opt::Optional).
If the children of the value are undefined, then:
- If
optisOpt::Essential, return an error. - If
optisOpt::Optional, return the input value.
sourcefn 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_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.
sourcefn 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 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.