Skip to main content

libutils_report/
mod.rs

1//^
2//^ HEAD
3//^
4
5//> HEAD -> FEATURES
6#![allow(incomplete_features)]
7#![feature(const_trait_impl)]
8#![feature(unsized_const_params)]
9#![feature(adt_const_params)]
10#![feature(default_field_values)]
11#![feature(generic_const_exprs)]
12
13//> HEAD -> MODULES
14mod state;
15#[cfg(test)]
16mod tests;
17
18//> HEAD -> PUBLIC STATE
19pub use state::{
20    Add,
21    Stay
22};
23
24//> HEAD -> STATE
25use state::{
26    State,
27    Main,
28    DerivedState
29};
30
31//> HEAD -> ISSUE
32use libutils_issue::Issue;
33
34//> HEAD -> TERMINAL
35use libutils_terminal::{
36    TERMINAL,
37    Console
38};
39
40//> HEAD -> THREAT
41use libutils_threat::{
42    Threat,
43    Severity
44};
45
46
47//^ 
48//^ REPORT
49//^ 
50
51//> REPORT -> STRUCT
52pub struct Report<Current: State> {
53    data: Current
54}
55
56//> REPORT -> IMPLEMENTATION
57impl Report<Main> {
58    pub fn new(name: &'static str) -> Self {Self {
59        data: Main {
60            chain: Vec::from([name])
61        }
62    }}
63}
64
65//> REPORT -> GIVE
66impl<Current: State> Report<Current> {
67    #[inline]
68    pub fn to<'valid, Following: DerivedState<'valid>>(&'valid mut self) -> Report<Following> {return Report {
69        data: Following::from(&mut self.data)
70    }}
71    #[inline]
72    pub fn warn<Object: Into<Issue>>(&self, object: Object) -> () {TERMINAL.write().problem(Threat {
73        object: object,
74        chain: self.data.chain(),
75        severity: Severity::Warning
76    })}
77    #[inline]
78    pub fn error<Object: Into<Issue>>(&self, object: Object) -> () {TERMINAL.write().problem(Threat {
79        object: object,
80        chain: self.data.chain(),
81        severity: Severity::Error
82    })}
83    #[inline]
84    pub fn critical<Object: Into<Issue>>(&self, object: Object) -> () {TERMINAL.write().problem(Threat {
85        object: object,
86        chain: self.data.chain(),
87        severity: Severity::Critical
88    })}
89}