chiark / gitweb /
report, hook in success
[hippotat.git] / src / reporter.rs
1 // Copyright 2021 Ian Jackson and contributors to Hippotat
2 // SPDX-License-Identifier: GPL-3.0-or-later
3 // There is NO WARRANTY.
4
5 use crate::prelude::*;
6
7 pub struct Reporter<'r> {
8   ic: &'r InstanceConfig,
9 }
10
11 impl<'r> Reporter<'r> {
12   pub fn new(ic: &'r InstanceConfig) -> Self { Reporter {
13     ic
14   } }
15   
16   pub fn success(&mut self) {
17     info!("{}: success", self.ic); // xxx
18   }
19   pub fn filter<T>(&mut self, req_num: Option<ReqNum>, r: Result<T,AE>)
20                    -> Option<T> {
21     match r {
22       Ok(t) => {
23         // xxx something something success
24         Some(t)
25       },
26       Err(e) => {
27         // xxx something something error
28         if let Some(req_num) = req_num {
29           warn!("{} #{}: {:?}", self.ic, req_num, e);
30         } else {
31           warn!("{}: {:?}", self.ic, e);
32         }
33         None
34       },
35     }
36   }
37 }