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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
use std::fmt;
use log::Record;
#[cfg(feature = "file")]
use serde_value::Value;
#[cfg(feature = "file")]
use serde::de;
#[cfg(feature = "file")]
use std::collections::BTreeMap;
#[cfg(feature = "file")]
use file::Deserializable;
#[cfg(feature = "threshold_filter")]
pub mod threshold;
pub trait Filter: fmt::Debug + Send + Sync + 'static {
fn filter(&self, record: &Record) -> Response;
}
#[cfg(feature = "file")]
impl Deserializable for Filter {
fn name() -> &'static str {
"filter"
}
}
pub enum Response {
Accept,
Neutral,
Reject,
}
#[derive(PartialEq, Eq, Debug)]
#[cfg(feature = "file")]
pub struct FilterConfig {
pub kind: String,
pub config: Value,
}
#[cfg(feature = "file")]
impl<'de> de::Deserialize<'de> for FilterConfig {
fn deserialize<D>(d: D) -> Result<FilterConfig, D::Error>
where
D: de::Deserializer<'de>,
{
let mut map = BTreeMap::<Value, Value>::deserialize(d)?;
let kind = match map.remove(&Value::String("kind".to_owned())) {
Some(kind) => kind.deserialize_into().map_err(|e| e.to_error())?,
None => return Err(de::Error::missing_field("kind")),
};
Ok(FilterConfig {
kind: kind,
config: Value::Map(map),
})
}
}