tera/builtins/filters/
mod.rs

1use std::collections::HashMap;
2
3use crate::errors::Result;
4use serde_json::value::Value;
5
6pub mod array;
7pub mod common;
8pub mod number;
9pub mod object;
10pub mod string;
11
12/// The filter function type definition
13pub trait Filter: Sync + Send {
14    /// The filter function type definition
15    fn filter(&self, value: &Value, args: &HashMap<String, Value>) -> Result<Value>;
16
17    /// Whether the current filter's output should be treated as safe, defaults to `false`
18    fn is_safe(&self) -> bool {
19        false
20    }
21}
22
23impl<F> Filter for F
24where
25    F: Fn(&Value, &HashMap<String, Value>) -> Result<Value> + Sync + Send,
26{
27    fn filter(&self, value: &Value, args: &HashMap<String, Value>) -> Result<Value> {
28        self(value, args)
29    }
30}