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