Skip to main content

g_err/
gerr_view.rs

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
10/// GErrView - GErr in borrowed form for reporting.
11pub struct GErrView<'a, C: Config, D> {
12    /// Error id.
13    pub id: Option<&'a C::Id>,
14    /// Error message.
15    pub message: &'a str,
16    /// Error code.
17    pub code: Option<&'a str>,
18    /// Error data.
19    pub data: Option<&'a D>,
20    /// Error tags.
21    pub tags: Option<&'a [Cow<'static, str>]>,
22    /// Error sources.
23    pub sources: Option<&'a [Source]>,
24    /// Error help hint.
25    pub help: Option<&'a str>,
26    /// Error location.
27    pub location: &'a ErrorLocation,
28    /// Error backtrace.
29    #[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}