1#![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(const_heap)]
12#![feature(generic_const_exprs)]
13
14mod state;
16#[cfg(test)]
17mod tests;
18
19pub use state::{
21 Add,
22 Stay
23};
24
25use state::{
27 State,
28 Main,
29 DerivedState
30};
31
32use libutils_issue::Issue;
34
35use libutils_terminal::{
37 TERMINAL,
38 Console
39};
40
41use libutils_threat::{
43 Threat,
44 Severity
45};
46
47
48pub struct Report<Current: State> {
54 data: Current
55}
56
57impl Report<Main> {
59 pub const fn new(name: &'static str) -> Self {
60 let mut chain = Vec::new();
61 chain.push(name);
62 Self {
63 data: Main {
64 chain: chain
65 }
66 }
67 }
68}
69
70impl<Current: State> Report<Current> {
72 #[inline]
73 pub fn to<'valid, Following: DerivedState<'valid>>(&'valid mut self) -> Report<Following> {return Report {
74 data: Following::from(&mut self.data)
75 }}
76 #[inline]
77 pub fn warn<Object: Into<Issue>, Wants: Default>(&self, object: Object) -> Wants {
78 TERMINAL.write().problem(Threat {
79 object: object,
80 chain: self.data.chain(),
81 severity: Severity::Warning
82 });
83 return Wants::default();
84 }
85 #[inline]
86 pub fn error<Object: Into<Issue>, Wants: Default>(&self, object: Object) -> Wants {
87 TERMINAL.write().problem(Threat {
88 object: object,
89 chain: self.data.chain(),
90 severity: Severity::Error
91 });
92 return Wants::default();
93 }
94 #[inline]
95 pub fn critical<Object: Into<Issue>, Wants: Default>(&self, object: Object) -> Wants {
96 TERMINAL.write().problem(Threat {
97 object: object,
98 chain: self.data.chain(),
99 severity: Severity::Critical
100 });
101 return Wants::default();
102 }
103}