pub trait ValT:
Clone
+ Display
+ From<bool>
+ From<isize>
+ From<String>
+ From<Range<Self>>
+ FromIterator<Self>
+ PartialEq
+ PartialOrd
+ Add<Output = ValR<Self>>
+ Sub<Output = ValR<Self>>
+ Mul<Output = ValR<Self>>
+ Div<Output = ValR<Self>>
+ Rem<Output = ValR<Self>>
+ Neg<Output = ValR<Self>> {
// Required methods
fn from_num(n: &str) -> ValR<Self>;
fn from_map<I: IntoIterator<Item = (Self, Self)>>(iter: I) -> ValR<Self>;
fn key_values(self) -> BoxIter<'static, ValR<(Self, Self), Self>>;
fn values(self) -> Box<dyn Iterator<Item = ValR<Self>>>;
fn index(self, index: &Self) -> ValR<Self>;
fn range(self, range: Range<&Self>) -> ValR<Self>;
fn map_values<'a, I: Iterator<Item = ValX<'a, Self>>>(
self,
opt: Opt,
f: impl Fn(Self) -> I,
) -> ValX<'a, Self>;
fn map_index<'a, I: Iterator<Item = ValX<'a, Self>>>(
self,
index: &Self,
opt: Opt,
f: impl Fn(Self) -> I,
) -> ValX<'a, Self>;
fn map_range<'a, I: Iterator<Item = ValX<'a, Self>>>(
self,
range: Range<&Self>,
opt: Opt,
f: impl Fn(Self) -> I,
) -> ValX<'a, Self>;
fn as_bool(&self) -> bool;
fn into_string(self) -> Self;
}Expand description
Values that can be processed by jaq.
Implement this trait if you want jaq to process your own type of values.
Required Methods§
Sourcefn from_num(n: &str) -> ValR<Self>
fn from_num(n: &str) -> ValR<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) -> ValR<Self>
fn from_map<I: IntoIterator<Item = (Self, Self)>>(iter: I) -> ValR<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 key_values(self) -> BoxIter<'static, ValR<(Self, Self), Self>>
fn key_values(self) -> BoxIter<'static, ValR<(Self, Self), Self>>
Yield the key-value pairs of a value.
This is used to collect the paths of .[].
It should yield any key for which value | .[key] is defined,
as well as its output.
Sourcefn values(self) -> Box<dyn Iterator<Item = ValR<Self>>>
fn values(self) -> Box<dyn Iterator<Item = ValR<Self>>>
Yield the children of a value.
This is used by .[].
Sourcefn index(self, index: &Self) -> ValR<Self>
fn index(self, index: &Self) -> ValR<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<&Self>) -> ValR<Self>
fn range(self, range: Range<&Self>) -> ValR<Self>
Yield a slice of the value with the given range.
This is used by .[s:e], .[s:], and .[:e].
Sourcefn map_values<'a, I: Iterator<Item = ValX<'a, Self>>>(
self,
opt: Opt,
f: impl Fn(Self) -> I,
) -> ValX<'a, Self>
fn map_values<'a, I: Iterator<Item = ValX<'a, Self>>>( self, opt: Opt, f: impl Fn(Self) -> I, ) -> ValX<'a, 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<'a, I: Iterator<Item = ValX<'a, Self>>>(
self,
index: &Self,
opt: Opt,
f: impl Fn(Self) -> I,
) -> ValX<'a, Self>
fn map_index<'a, I: Iterator<Item = ValX<'a, Self>>>( self, index: &Self, opt: Opt, f: impl Fn(Self) -> I, ) -> ValX<'a, 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<'a, I: Iterator<Item = ValX<'a, Self>>>(
self,
range: Range<&Self>,
opt: Opt,
f: impl Fn(Self) -> I,
) -> ValX<'a, Self>
fn map_range<'a, I: Iterator<Item = ValX<'a, Self>>>( self, range: Range<&Self>, opt: Opt, f: impl Fn(Self) -> I, ) -> ValX<'a, 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.
Sourcefn as_bool(&self) -> bool
fn as_bool(&self) -> bool
Return a boolean representation of the value.
This is used by if v then ....
Sourcefn into_string(self) -> Self
fn into_string(self) -> Self
Convert value into a string value.
This is used by "\(v)".
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".