Skip to main content

grp_core/error/errors/
macro.rs

1#[macro_export]
2macro_rules! empty_notes {
3    () => { Vec::<String>::new() };
4}
5
6#[macro_export]
7macro_rules! make_error {
8    (
9        $notes:ident, 
10        $type:expr,
11        $message:expr,
12        $number:literal of
13            $( $content:expr ),* $(,)?
14    ) => {{
15        let mut content_length: usize = $number;
16        let notes_legth = $notes.len();
17        if notes_legth > 0 { content_length += $notes.len() + 2; }
18        let mut content: Vec<String> = Vec::with_capacity(content_length);
19        
20        $( content.push($content); )*
21        
22        if notes_legth > 0 { 
23            content.push(cformat!(""));
24            content.push(cformat!("<g># notes</>"));
25            content.extend($crate::error::tools::Notes::as_notes($notes.iter()));
26        }
27        
28        $crate::error::structs::Error {
29            etype: $type.to_string(),
30            message: $message.to_string(),
31            content: content,
32        }
33    }};
34    (
35        $type:expr,
36        $message:expr,
37        $number:literal of
38            $( $content:expr ),* $(,)?
39    ) => {{
40        let mut content: Vec<String> = Vec::with_capacity($number);
41        
42        $( content.push($content); )*
43        
44        $crate::error::structs::Error {
45            etype: $type.to_string(),
46            message: $message.to_string(),
47            content: content,
48        }
49    }};
50}