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(const_heap)]
12#![feature(const_default)]
13#![feature(generic_const_exprs)]
14
15//> HEAD -> MODULES
16mod state;
17#[cfg(test)]
18mod tests;
19
20//> HEAD -> PUBLIC STATE
21pub use state::{
22    Same,
23    Name
24};
25
26//> HEAD -> STATE
27use state::{
28    State,
29    Main,
30    DerivedState
31};
32
33//> HEAD -> ISSUE
34use libutils_issue::Issue;
35
36//> HEAD -> TERMINAL
37use libutils_terminal::TERMINAL;
38
39//> HEAD -> THREAT
40use libutils_threat::Threat;
41
42//> HEAD -> CONSOLE
43use libutils_console::Console;
44
45
46//^ 
47//^ REPORT
48//^ 
49
50//> REPORT -> STRUCT
51pub struct Report<Current: State> {
52    data: Current
53}
54
55//> REPORT -> IMPLEMENTATION
56impl Report<Main> {
57    pub const fn new(name: &'static str) -> Self {
58        let mut chain = Vec::new();
59        chain.push(name);
60        return Self {
61            data: Main {
62                chain: chain
63            }
64        };
65    }
66}
67
68//> REPORT -> DEFAULT
69const impl Default for Report<Main> {
70    fn default() -> Self {return Self::new("Main")}
71}
72
73//> REPORT -> IMPLEMENTATION
74impl<Current: State> Report<Current> {
75    #[inline]
76    pub fn to<'valid, Following: DerivedState<'valid>>(&'valid mut self) -> Report<Following> {return Report {
77        data: Following::convert(&mut self.data)
78    }}
79    #[inline]
80    pub fn issue<Object: Into<Issue>, Type>(&self, object: Object) -> Option<Type> {
81        TERMINAL.problem(Threat {
82            issue: object.into(),
83            chain: self.data.chain()
84        });
85        TERMINAL.sync();
86        return None;
87    }
88}