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