1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use std::error::Error;
pub trait ErrorCollector {
fn collect(&mut self, name: String, e: Box<dyn Error>);
fn get_results(&mut self) -> Vec<(String, String)>;
}
impl ErrorCollector for Vec<(String, String)> {
fn collect(&mut self, name: String, e: Box<dyn Error>) {
self.push((name, e.to_string()))
}
fn get_results(&mut self) -> Vec<(String, String)> {
let nv = self.clone();
self.clear();
nv
}
}
pub struct SilentCollector;
impl ErrorCollector for SilentCollector {
fn collect(&mut self, _name: String, _e: Box<dyn Error>) {
}
fn get_results(&mut self) -> Vec<(String, String)> {
vec![]
}
}