Skip to main content

difflore_core/domain/
rule_view.rs

1//! Common view over rule-bearing records used by helpers in `origins`.
2
3pub trait RuleView {
4    fn id(&self) -> &str;
5    fn content(&self) -> &str;
6    fn origin(&self) -> &str;
7    fn confidence(&self) -> Option<f64>;
8}
9
10#[cfg(test)]
11mod tests {
12    use super::*;
13
14    struct Fake {
15        id: String,
16        content: String,
17        origin: String,
18        conf: Option<f64>,
19    }
20
21    impl RuleView for Fake {
22        fn id(&self) -> &str {
23            &self.id
24        }
25        fn content(&self) -> &str {
26            &self.content
27        }
28        fn origin(&self) -> &str {
29            &self.origin
30        }
31        fn confidence(&self) -> Option<f64> {
32            self.conf
33        }
34    }
35
36    #[test]
37    fn trait_basic_dispatch() {
38        let r = Fake {
39            id: "a".into(),
40            content: "c".into(),
41            origin: "manual".into(),
42            conf: Some(0.7),
43        };
44        assert_eq!(r.id(), "a");
45        assert_eq!(r.content(), "c");
46        assert_eq!(r.origin(), "manual");
47        assert_eq!(r.confidence(), Some(0.7));
48    }
49}