1use crate::rbe1::Rbe;
2use crate::rbe_error::RbeError;
3use crate::Key;
4use crate::Ref;
5use crate::Value;
6use serde::{Deserialize, Serialize};
7use std::fmt::Debug;
8use std::fmt::Display;
9use std::fmt::Formatter;
10
11type RbeAndRbeError<K, V, R> = (Box<Rbe<K, V, R>>, RbeError<K, V, R>);
12
13#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)]
14pub struct Failures<K, V, R>
15where
16 K: Key,
17 V: Value,
18 R: Ref,
19{
20 fs: Vec<RbeAndRbeError<K, V, R>>,
21}
22
23impl<K, V, R> Failures<K, V, R>
24where
25 K: Key,
26 V: Value,
27 R: Ref,
28{
29 pub fn new() -> Self {
30 Self { fs: Vec::new() }
31 }
32
33 pub fn push(&mut self, expr: Rbe<K, V, R>, err: RbeError<K, V, R>) {
34 self.fs.push((Box::new(expr), err));
35 }
36}
37
38impl<K, V, R> Default for Failures<K, V, R>
39where
40 K: Key,
41 V: Value,
42 R: Ref,
43{
44 fn default() -> Self {
45 Self::new()
46 }
47}
48
49impl<K, V, R> Display for Failures<K, V, R>
50where
51 K: Key,
52 V: Value,
53 R: Ref,
54{
55 fn fmt(&self, dest: &mut Formatter<'_>) -> Result<(), std::fmt::Error> {
56 for (expr, err) in &self.fs {
57 writeln!(dest, "Error at {expr}: {err}")?;
58 }
59 Ok(())
60 }
61}