except_plugin/core/
unsupported.rs

1//! # UnSupported Operation Exception
2//! ```txt
3//! @author:syf20020816@Outlook.com
4//! @date:2023/8/15
5//! @version:0.0.1
6//! @description:
7//! ```
8
9use std::error::Error;
10use std::path::{PathBuf};
11use std::fmt::{Debug, Display, Formatter};
12use std::time::{Duration, SystemTime, UNIX_EPOCH};
13use super::{UNSUPPORTED_OPERATION_MSG, Reasons,UnSupportedReasons,ReasonParamImpl, SuperBuilderImpl, ExceptionLevel, NewFrom, FromBuilder, CommonParamImpl, Exception, Exceptions, UnSupportedOpExceptionBuilder, ExceptionCode, DerefException};
14use crate::{display_err_impl, exception_impl, common_param_impl, reason_param_impl};
15
16
17/// # UnSupportedOperationException
18/// - code: exception code
19/// - msg: exception msg
20/// - line: error line
21/// - path: error file path
22/// - level: exception level
23/// - reason: reason for error
24#[derive(Debug, Clone, PartialEq)]
25pub struct UnSupportedOpException {
26    code: u32,
27    msg: String,
28    line: u32,
29    path: PathBuf,
30    level: ExceptionLevel,
31    reason: Reasons,
32    timestamp: Duration,
33}
34
35impl Default for UnSupportedOpException {
36    fn default() -> Self {
37        UnSupportedOpException {
38            code: ExceptionCode::UNSUPPORTED_OPERATION,
39            msg: String::from(UNSUPPORTED_OPERATION_MSG),
40            line: 0,
41            path: PathBuf::new(),
42            level: ExceptionLevel::Info,
43            reason: Reasons::UnSupported(UnSupportedReasons::Other),
44            timestamp: SystemTime::now().duration_since(UNIX_EPOCH).unwrap(),
45        }
46    }
47}
48
49impl NewFrom for UnSupportedOpException {
50    type Builder = UnSupportedOpExceptionBuilder;
51    fn new() -> Self::Builder {
52        UnSupportedOpExceptionBuilder::new()
53    }
54    fn from_super(e: Box<dyn Exception>) -> Self where Self: Sized {
55        UnSupportedOpException {
56            code: e.code(),
57            msg: String::from(e.msg()),
58            level: e.level(),
59            reason: Reasons::UnSupported(UnSupportedReasons::Other),
60            path: PathBuf::new(),
61            line: 0,
62            timestamp: e.timestamp(),
63        }
64    }
65}
66
67impl FromBuilder for UnSupportedOpException {
68    type Input = UnSupportedOpExceptionBuilder;
69    type Output = UnSupportedOpException;
70    fn from_builder(builder: &Self::Input) -> Self::Output {
71        Self::Output {
72            code: builder.code(),
73            msg: String::from(builder.msg()),
74            level: builder.level(),
75            reason: builder.reason(),
76            line: builder.line(),
77            path: builder.path(),
78            timestamp: builder.timestamp(),
79        }
80    }
81}
82
83display_err_impl!(UnSupportedOpException);
84
85exception_impl!(UnSupportedOpException,Exceptions::UnSupportedOperation);
86
87common_param_impl!(UnSupportedOpException);
88
89reason_param_impl!(UnSupportedOpException);
90
91impl DerefException for UnSupportedOpException {
92    fn deref_mut_exception(&mut self) -> Self {
93        UnSupportedOpException {
94            code: self.code(),
95            msg: String::from(self.msg()),
96            line: self.line(),
97            path: self.path(),
98            level: self.level(),
99            reason: self.reason(),
100            timestamp: self.timestamp(),
101        }
102    }
103}
104
105