except_plugin/core/
index.rs

1//! # Index Out of bounds Exception
2//! ```txt
3//! @author:syf20020816@Outlook.com
4//! @date:2023/8/14
5//! @version:0.0.1
6//! @description:
7//! ```
8
9use std::time::{SystemTime,Duration,UNIX_EPOCH};
10use std::error::Error;
11use std::path::{PathBuf};
12use std::fmt::{Debug, Display, Formatter};
13use super::{OUT_OF_BOUNDS_MSG, SuperBuilderImpl, ExceptionLevel, NewFrom, FromBuilder, CommonParamImpl, OutOfBoundsParamImpl, TargetParamImpl, Exception, Exceptions, ArrayIndexOutOfBoundsBuilder, ExceptionCode, DerefException};
14use crate::{display_err_impl, exception_impl, common_param_impl, target_param_impl, out_of_bounds_impl};
15
16/// # ArrayIndexOutofBoundsException
17/// - code: exception code
18/// - msg: exception msg
19/// - line: error line
20/// - path: error file path
21/// - level: exception level
22/// - target: null pointer target
23/// - len: array length
24/// - index: which index cause out of bounds
25#[derive(Debug, Clone, PartialEq)]
26pub struct ArrayIndexOutOfBoundsException {
27    code: u32,
28    msg: String,
29    line: u32,
30    path: PathBuf,
31    level: ExceptionLevel,
32    target: Option<String>,
33    len: usize,
34    index: usize,
35    timestamp:Duration,
36}
37
38impl Default for ArrayIndexOutOfBoundsException {
39    fn default() -> Self {
40        ArrayIndexOutOfBoundsException {
41            code: ExceptionCode::NULL_POINTER,
42            msg: String::from(OUT_OF_BOUNDS_MSG),
43            line: 0,
44            path: PathBuf::new(),
45            level: ExceptionLevel::Info,
46            target: None,
47            len: 0,
48            index: 0,
49            timestamp: SystemTime::now().duration_since(UNIX_EPOCH).unwrap(),
50        }
51    }
52}
53
54impl NewFrom for ArrayIndexOutOfBoundsException {
55    type Builder = ArrayIndexOutOfBoundsBuilder;
56    fn new() -> Self::Builder {
57        ArrayIndexOutOfBoundsBuilder::new()
58    }
59    fn from_super(e: Box<dyn Exception>) -> Self where Self: Sized {
60        ArrayIndexOutOfBoundsException {
61            code: e.code(),
62            msg: String::from(e.msg()),
63            level: e.level(),
64            path: PathBuf::new(),
65            line: 0,
66            target: None,
67            len: 0,
68            index: 0,
69            timestamp: e.timestamp()
70        }
71    }
72}
73
74impl FromBuilder for ArrayIndexOutOfBoundsException {
75    type Input = ArrayIndexOutOfBoundsBuilder;
76    type Output = ArrayIndexOutOfBoundsException;
77    fn from_builder(builder: &Self::Input) -> Self::Output {
78        Self::Output {
79            code: builder.code(),
80            msg: String::from(builder.msg()),
81            level: builder.level(),
82            line: builder.line(),
83            path: builder.path(),
84            target: Some(builder.target().to_string()),
85            len: builder.len(),
86            index: builder.index(),
87            timestamp: builder.timestamp()
88        }
89    }
90}
91
92display_err_impl!(ArrayIndexOutOfBoundsException);
93
94exception_impl!(ArrayIndexOutOfBoundsException,Exceptions::ArrayIndexOutOfBounds);
95
96common_param_impl!(ArrayIndexOutOfBoundsException);
97
98target_param_impl!(ArrayIndexOutOfBoundsException);
99
100out_of_bounds_impl!(ArrayIndexOutOfBoundsException);
101
102impl DerefException for ArrayIndexOutOfBoundsException {
103    fn deref_mut_exception(&mut self) -> Self {
104        ArrayIndexOutOfBoundsException {
105            code: self.code(),
106            msg: String::from(self.msg()),
107            line: self.line(),
108            path: self.path(),
109            level: self.level(),
110            target: Some(self.target().to_string()),
111            len: self.len(),
112            index: self.index(),
113            timestamp: self.timestamp()
114        }
115    }
116}
117