except_plugin/core/
easy.rs1use std::time::{SystemTime,Duration,UNIX_EPOCH};
10use std::path::PathBuf;
11use std::error::Error;
12use std::fmt::{Debug, Display, Formatter};
13use super::{NewFrom, FromBuilder, EasyExceptionBuilder, CommonParamImpl, EASY_MSG, ExceptionCode, SuperBuilderImpl};
14use crate::{DerefException, display_err_impl, Exception, exception_impl, common_param_impl, ExceptionLevel, Exceptions};
15
16#[derive(Debug, Clone, PartialEq)]
23pub struct EasyException {
24 code: u32,
25 msg: String,
26 line: u32,
27 path: PathBuf,
28 level: ExceptionLevel,
29 timestamp: Duration,
30}
31
32impl Default for EasyException {
33 fn default() -> Self {
34 EasyException {
35 code: ExceptionCode::COMMON,
36 msg: String::from(EASY_MSG),
37 line: 0,
38 path: PathBuf::new(),
39 level: ExceptionLevel::Info,
40 timestamp: SystemTime::now().duration_since(UNIX_EPOCH).unwrap(),
41 }
42 }
43}
44
45impl NewFrom for EasyException {
46 type Builder = EasyExceptionBuilder;
47 fn new() -> Self::Builder {
48 EasyExceptionBuilder::new()
49 }
50 fn from_super(e: Box<dyn Exception>) -> Self where Self: Sized {
51 EasyException {
52 code: e.code(),
53 msg: String::from(e.msg()),
54 level: e.level(),
55 path: PathBuf::new(),
56 line: 0,
57 timestamp: e.timestamp()
58 }
59 }
60}
61
62impl FromBuilder for EasyException {
63 type Input = EasyExceptionBuilder;
64 type Output = EasyException;
65 fn from_builder(builder: &Self::Input) -> Self::Output {
66 Self::Output {
67 code: builder.code(),
68 msg: String::from(builder.msg()),
69 level: builder.level(),
70 line: builder.line(),
71 path: builder.path(),
72 timestamp: builder.timestamp()
73 }
74 }
75}
76
77display_err_impl!(EasyException);
78
79exception_impl!(EasyException,Exceptions::Easy);
80
81common_param_impl!(EasyException);
82
83impl DerefException for EasyException {
84 fn deref_mut_exception(&mut self) -> Self {
85 EasyException {
86 code: self.code(),
87 msg: String::from(self.msg()),
88 line: self.line(),
89 path: self.path(),
90 level: self.level(),
91 timestamp: self.timestamp()
92 }
93 }
94}