1extern crate alloc;
2
3use alloc::string::String;
4use core::fmt::{Debug, Display};
5
6mod pretty_report;
7pub use pretty_report::PrettyReport;
8
9mod markdown_report;
10pub use markdown_report::MarkdownReport;
11
12mod trace_report;
13pub use trace_report::TraceReport;
14
15#[cfg(feature = "serde")]
16mod json_report;
17
18#[cfg(feature = "serde")]
19mod json_data;
20
21#[cfg(feature = "serde")]
22pub use json_data::{DisplayJsonData, JsonData, LocationJsonData, SourceJsonData};
23
24#[cfg(feature = "serde")]
25pub use json_report::JsonReport;
26
27use crate::{Config, gerr::GErr, gerr_view::GErrView};
28
29pub trait Report {
33 #[cfg(not(feature = "serde"))]
35 fn report<E, C: Config, D>(err: &E) -> String
36 where
37 for<'a> &'a E: Into<GErrView<'a, C, D>>,
38 C::Id: Display,
39 D: Debug;
40
41 #[cfg(feature = "serde")]
45 fn report<E, C: Config, D>(err: &E) -> String
46 where
47 for<'a> &'a E: Into<GErrView<'a, C, D>>,
48 C::Id: Display + serde::Serialize,
49 D: Debug + serde::Serialize;
50}
51
52#[cfg(not(feature = "serde"))]
53impl<C: Config, D> GErr<C, D>
54where
55 C::Id: Display,
56 D: Debug,
57{
58 pub fn report(&self) -> String {
60 PrettyReport::report::<_, C, D>(self)
61 }
62
63 pub fn report_as<R>(&self) -> String
65 where
66 R: Report,
67 {
68 R::report::<_, C, D>(self)
69 }
70}
71
72#[cfg(feature = "serde")]
73impl<C: Config, D> GErr<C, D>
74where
75 C::Id: Display + serde::Serialize,
76 D: Debug + serde::Serialize,
77{
78 #[inline]
80 pub fn report(&self) -> String {
81 PrettyReport::report::<_, C, D>(self)
82 }
83
84 #[inline]
86 pub fn report_as<R>(&self) -> String
87 where
88 R: Report,
89 {
90 R::report::<_, C, D>(self)
91 }
92}
93
94#[cfg(feature = "serde")]
95impl<C: Config, D> GErr<C, D>
96where
97 C::Id: serde::Serialize,
98 D: serde::Serialize,
99{
100 #[inline]
102 pub fn json_data(&self) -> JsonData {
103 JsonReport::data(self)
104 }
105
106 #[inline]
108 pub fn display_json_data(&self) -> DisplayJsonData {
109 JsonReport::display_data(self)
110 }
111}