1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright (C) 2020 - 2022, J2 Innovations
//! Haystack Filtered implementations
use Filter;
/// Generic trait that enables filtering evaluation over an object.
/// Specifically this would be implemented by [Dict](crate::val::Dict)
/// and [Grid](crate::val::Grid).
///
// # Example
/// ```
/// use libhaystack::dict;
/// use libhaystack::val::{Dict, Value};
/// use libhaystack::filter::{Filter, Filtered};
///
/// let dict = dict!{
/// "site" => Value::make_marker(),
/// "dis" => Value::make_str("Some site")
/// };
/// assert!(dict.filter(&Filter::try_from("site and dis").expect("Filter")));
/// ```
/// Generic trait that enables filtering evaluation over a list of objects
/// that implement the `Filtered` trait.
/// Specifically this would be implemented by [Grid](crate::val::Grid).
///
/// # Example
/// ```
/// use libhaystack::dict;
/// use libhaystack::val::{Dict, Grid, Value};
/// use libhaystack::filter::{Filter, ListFiltered};
///
/// let rows = vec![
/// dict! { "a" => Value::make_marker()},
/// dict! { "b" => Value::make_marker()}];
/// let grid = Grid::make_from_dicts(rows);
/// let res = grid.filter_all(&Filter::try_from("a or b").unwrap());
/// assert_eq!(res.len(), 2);
/// ```