libtest2_harness/notify/
mod.rs

1mod json;
2#[cfg(not(feature = "color"))]
3mod no_style;
4mod pretty;
5#[cfg(feature = "color")]
6mod style;
7mod summary;
8mod terse;
9
10pub(crate) use json::*;
11#[cfg(not(feature = "color"))]
12pub(crate) use no_style::*;
13pub(crate) use pretty::*;
14#[cfg(feature = "color")]
15pub(crate) use style::*;
16pub(crate) use summary::*;
17pub(crate) use terse::*;
18
19pub(crate) trait Notifier {
20    fn threaded(&mut self, _yes: bool) {}
21
22    fn notify(&mut self, event: Event) -> std::io::Result<()>;
23}
24
25#[derive(Clone)]
26pub(crate) struct ArcNotifier {
27    inner: std::sync::Arc<std::sync::Mutex<dyn Notifier + Send>>,
28}
29
30impl ArcNotifier {
31    pub(crate) fn new(inner: impl Notifier + Send + 'static) -> Self {
32        Self {
33            inner: std::sync::Arc::new(std::sync::Mutex::new(inner)),
34        }
35    }
36
37    pub(crate) fn threaded(&self, yes: bool) {
38        let mut notifier = match self.inner.lock() {
39            Ok(notifier) => notifier,
40            Err(poison) => poison.into_inner(),
41        };
42        notifier.threaded(yes);
43    }
44
45    pub(crate) fn notify(&self, event: Event) -> std::io::Result<()> {
46        let mut notifier = match self.inner.lock() {
47            Ok(notifier) => notifier,
48            Err(poison) => poison.into_inner(),
49        };
50        notifier.notify(event)
51    }
52}
53
54pub(crate) use libtest_json::*;
55
56pub use libtest_json::RunMode;