1extern crate alloc;
2
3use alloc::borrow::Cow;
4
5#[cfg(feature = "backtrace")]
6use std::backtrace::Backtrace;
7
8use crate::gerr::{Config, ErrorLocation, GErr, Source};
9
10pub struct GErrView<'a, C: Config, D> {
12 pub id: Option<&'a C::Id>,
14 pub message: &'a str,
16 pub code: Option<&'a str>,
18 pub data: Option<&'a D>,
20 pub tags: Option<&'a [Cow<'static, str>]>,
22 pub sources: Option<&'a [Source]>,
24 pub help: Option<&'a str>,
26 pub location: &'a ErrorLocation,
28 #[cfg(feature = "backtrace")]
30 pub backtrace: &'a Backtrace,
31}
32
33impl<'a, C: Config, D> From<&'a GErr<C, D>> for GErrView<'a, C, D> {
34 fn from(err: &'a GErr<C, D>) -> Self {
35 Self {
36 id: err.id(),
37 message: err.message(),
38 code: err.code(),
39
40 data: err.data(),
41
42 tags: err.tags(),
43
44 sources: err.sources(),
45
46 help: err.help(),
47
48 location: err.location(),
49
50 #[cfg(feature = "backtrace")]
51 backtrace: err.backtrace(),
52 }
53 }
54}