Skip to main content

g_err/
gerr_box.rs

1extern crate alloc;
2
3use alloc::boxed::Box;
4
5use crate::types::DefaultConfig;
6use crate::{Config, GErr, GErrSource, GErrView, NoData};
7use crate::{DataSource, IdSource};
8
9/// Alias for Box of GErr.
10///
11/// For smaller size error type, but heap-allocated, use this.
12///
13/// Just like GErr, C(Config) is defaulted to DefaultConfig and D(Data) is defaulted to NoData.
14pub type GErrBox<C = DefaultConfig, D = NoData> = Box<GErr<C, D>>;
15
16#[cfg(not(feature = "serde"))]
17impl<C: Config, D> From<Box<GErr<C, D>>> for GErrSource
18where
19    C::Id: IdSource + 'static,
20    D: DataSource + 'static,
21{
22    fn from(gerr: Box<GErr<C, D>>) -> Self {
23        (*gerr).into()
24    }
25}
26
27#[cfg(feature = "serde")]
28impl<C: Config, D> From<Box<GErr<C, D>>> for GErrSource
29where
30    C::Id: ::serde::Serialize + IdSource + 'static,
31    D: ::serde::Serialize + DataSource + 'static,
32{
33    fn from(gerr: Box<GErr<C, D>>) -> Self {
34        (*gerr).into()
35    }
36}
37
38impl<'a, C: Config, D> From<&'a GErrBox<C, D>> for GErrView<'a, C, D> {
39    fn from(err: &'a GErrBox<C, D>) -> Self {
40        (&**err).into()
41    }
42}
43
44impl<T, C: Config, D> From<GErrBox<C, D>> for core::result::Result<T, GErrBox<C, D>> {
45    #[inline]
46    fn from(value: GErrBox<C, D>) -> Self {
47        core::result::Result::Err(value)
48    }
49}