1#[derive(Debug)]
8pub struct DispatchResult {
9 results: Vec<Result<(), Box<dyn std::error::Error + Send + Sync>>>,
10 blocked: bool,
11 listener_count: usize,
12}
13
14impl DispatchResult {
15 pub(crate) fn new(results: Vec<Result<(), Box<dyn std::error::Error + Send + Sync>>>) -> Self {
16 let listener_count = results.len();
17 Self {
18 results,
19 blocked: false,
20 listener_count,
21 }
22 }
23
24 pub(crate) fn blocked() -> Self {
25 Self {
26 results: Vec::new(),
27 blocked: true,
28 listener_count: 0,
29 }
30 }
31
32 pub fn is_blocked(&self) -> bool {
34 self.blocked
35 }
36
37 pub fn listener_count(&self) -> usize {
39 self.listener_count
40 }
41
42 pub fn success_count(&self) -> usize {
44 self.results.iter().filter(|r| r.is_ok()).count()
45 }
46
47 pub fn error_count(&self) -> usize {
49 self.results.iter().filter(|r| r.is_err()).count()
50 }
51
52 pub fn errors(&self) -> Vec<&(dyn std::error::Error + Send + Sync)> {
54 self.results
55 .iter()
56 .filter_map(|r| r.as_ref().err())
57 .map(|e| e.as_ref())
58 .collect()
59 }
60
61 pub fn all_succeeded(&self) -> bool {
63 !self.blocked && self.results.iter().all(|r| r.is_ok())
64 }
65
66 pub fn has_errors(&self) -> bool {
68 self.results.iter().any(|r| r.is_err())
69 }
70}