pub struct Query<PR> { /* private fields */ }Expand description
The Query is an builder to configure the query(). It is possible, to extend the Operators in the modul: crate::operator.
Example
Create your own operator:
use fltrs::{value::Value, PathResolver, Predicate, Query, Result, query};
fn upper_eq<PR: PathResolver>(idx: usize, v: Value) -> Result<Predicate<PR>> {
Ok(Box::new(
move |pr| {
if let Value::Text(t) = &v {
return pr.value(idx).as_string().to_uppercase().eq(&t.to_uppercase());
}
false
}
))
}
let query = Query::build()
.operators(&[("upper_eq", upper_eq)])
.query(r#" upper_eq "ab" "#)
.unwrap();
let result: Vec<&str> = ["yz", "aB", "Ab", "xY"].into_iter().filter(query).collect();
assert_eq!(vec!["aB", "Ab"], result);
Create your own as [convert function] (for example: conversion of units):
use fltrs::{value::Value, PathResolver, Predicate, Query, Result, query};
let query = Query::build()
.as_value_fn(&[("kbyte", |v| {
if let Value::Int(x) = v {
return Value::Int(x * 1024);
}
v
}
)])
.query(r#" > 1 as kbyte and < 6 as kbyte "#)
.unwrap();
// list of bytes
let result: Vec<i32> = [100, 1025, 7000, 4001].into_iter().filter(query).collect();
assert_eq!(vec![1025, 4001], result);
Implementations
sourceimpl<PR: PathResolver + 'static> Query<PR>
impl<PR: PathResolver + 'static> Query<PR>
Auto Trait Implementations
impl<PR> RefUnwindSafe for Query<PR>
impl<PR> Send for Query<PR>
impl<PR> Sync for Query<PR>
impl<PR> Unpin for Query<PR>
impl<PR> UnwindSafe for Query<PR>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more