• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 use quote::ToTokens;
2 use std::fmt::Display;
3 use syn::{Error, Result};
4 
5 pub struct Errors {
6     errors: Vec<Error>,
7 }
8 
9 impl Errors {
new() -> Self10     pub fn new() -> Self {
11         Errors { errors: Vec::new() }
12     }
13 
error(&mut self, sp: impl ToTokens, msg: impl Display)14     pub fn error(&mut self, sp: impl ToTokens, msg: impl Display) {
15         self.errors.push(Error::new_spanned(sp, msg));
16     }
17 
push(&mut self, error: Error)18     pub fn push(&mut self, error: Error) {
19         self.errors.push(error);
20     }
21 
propagate(&mut self) -> Result<()>22     pub fn propagate(&mut self) -> Result<()> {
23         let mut iter = self.errors.drain(..);
24         let mut all_errors = match iter.next() {
25             Some(err) => err,
26             None => return Ok(()),
27         };
28         for err in iter {
29             all_errors.combine(err);
30         }
31         Err(all_errors)
32     }
33 }
34