eipw_lint/
reporters.rs

1/*
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
5 */
6
7pub mod additional_help;
8pub mod count;
9pub mod json;
10pub mod null;
11pub mod text;
12
13use eipw_snippets::Message;
14
15pub use self::additional_help::AdditionalHelp;
16pub use self::count::Count;
17pub use self::json::Json;
18pub use self::null::Null;
19pub use self::text::Text;
20
21use std::fmt::{self, Debug};
22
23#[derive(Debug)]
24pub struct Error {
25    source: Box<dyn std::error::Error + 'static>,
26}
27
28impl fmt::Display for Error {
29    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
30        write!(f, "report failed: {}", self.source)
31    }
32}
33
34impl std::error::Error for Error {
35    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
36        Some(&*self.source)
37    }
38}
39
40impl Error {
41    pub fn new<S>(s: S) -> Self
42    where
43        S: std::error::Error + 'static,
44    {
45        Self {
46            source: Box::new(s),
47        }
48    }
49}
50
51pub trait Reporter {
52    fn report(&self, snippet: Message<'_>) -> Result<(), Error>;
53}