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::{
38    Console,
39    TERMINAL
40};
41
42//> HEAD -> THREAT
43use libutils_threat::Threat;
44
45//> HEAD -> CAGE
46use libutils_cage::Cage;
47
48
49//^ 
50//^ REPORT
51//^ 
52
53//> REPORT -> STRUCT
54pub struct Report<Current: State> {
55    data: Current,
56    cage: &'static Cage<dyn Console>
57}
58
59//> REPORT -> IMPLEMENTATION
60impl Report<Main> {
61    pub const fn new(name: &'static str) -> Self {return Self::with(name, &TERMINAL)}
62    pub const fn with(name: &'static str, cage: &'static Cage<dyn Console>) -> Self {
63        let mut chain = Vec::new();
64        chain.push(name);
65        return Self {
66            data: Main {
67                chain: chain,
68            },
69            cage: cage
70        };
71    }
72}
73
74//> REPORT -> DEFAULT
75const impl Default for Report<Main> {
76    fn default() -> Self {return Self::new("Main")}
77}
78
79//> REPORT -> IMPLEMENTATION
80impl<Current: State> Report<Current> {
81    #[inline]
82    pub fn to<'valid, Following: DerivedState<'valid>>(&'valid mut self) -> Report<Following> {return Report {
83        data: Following::from(&mut self.data),
84        cage: self.cage
85    }}
86    #[inline]
87    pub fn issue<Object: Into<Issue>, Type>(&self, object: Object) -> Option<Type> {
88        let mut console = self.cage.write();
89        console.problem(Threat {
90            issue: object.into(),
91            chain: self.data.chain()
92        });
93        console.sync();
94        return None;
95    }
96}