chiark / gitweb /
prep for moving lock into reporter
[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 report<T>(&self, req_num: Option<ReqNum>, r: Result<T,AE>)
17                    -> Option<T> {
18     match r {
19       Ok(t) => {
20         // xxx something something success
21         Some(t)
22       },
23       Err(e) => {
24         // xxx something something error
25         if let Some(req_num) = req_num {
26           warn!("{} #{}: {:?}", self.ic, req_num, e);
27         } else {
28           warn!("{}: {:?}", self.ic, e);
29         }
30         None
31       },
32     }
33   }
34 }