1mod future_ext;
2
3#[cfg(feature = "prometheus")]
4pub mod prometheus;
5
6pub use future_ext::{ObservedFuture, ObservedFutureExt};
7
8#[allow(unused_variables)]
14pub trait Observer<Out: ?Sized> {
15 fn on_first_poll(&mut self) {}
17
18 fn on_poll(&mut self) {}
20
21 fn on_poll_ready(&mut self, output: &Out) {}
23
24 fn on_finish(&mut self, output: Option<&Out>) {}
28
29 fn on_drop(&mut self) {}
32}
33
34pub trait AsStatusLabel {
36 fn as_status_label(&self) -> String;
38}
39
40impl<T, E: AsStatusLabel> AsStatusLabel for Result<T, E> {
41 fn as_status_label(&self) -> String {
42 match self {
43 Ok(_) => "ok".to_owned(),
44 Err(err) => err.as_status_label(),
45 }
46 }
47}
48
49impl AsStatusLabel for str {
50 fn as_status_label(&self) -> String {
51 self.to_string()
52 }
53}
54
55#[allow(non_snake_case)]
56mod macro_impl {
57 use super::Observer;
58
59 macro_rules! impl_observer_tuple {
60 ($($t:tt)+) => {
61 impl<Out: ?Sized, $($t),+> Observer<Out> for ($($t),+,)
62 where
63 $($t: Observer<Out>),+
64 {
65 fn on_first_poll(&mut self) {
66 let ($($t),+,) = self;
67 $($t.on_first_poll();)+
68 }
69
70 fn on_poll(&mut self) {
71 let ($($t),+,) = self;
72 $($t.on_poll();)+
73 }
74
75 fn on_poll_ready(&mut self, output: &Out) {
76 let ($($t),+,) = self;
77 $($t.on_poll_ready(output);)+
78 }
79
80 fn on_finish(&mut self, output: Option<&Out>) {
81 let ($($t),+,) = self;
82 $($t.on_finish(output);)+
83 }
84
85 fn on_drop(&mut self) {
86 let ($($t),+,) = self;
87 $($t.on_drop();)+
88 }
89 }
90 }
91 }
92
93 impl_observer_tuple! { O1 }
94 impl_observer_tuple! { O1 O2 }
95 impl_observer_tuple! { O1 O2 O3 }
96 impl_observer_tuple! { O1 O2 O3 O4 }
97 impl_observer_tuple! { O1 O2 O3 O4 O5 }
98 impl_observer_tuple! { O1 O2 O3 O4 O5 O6 }
99 impl_observer_tuple! { O1 O2 O3 O4 O5 O6 O7 }
100 impl_observer_tuple! { O1 O2 O3 O4 O5 O6 O7 O8 }
101}