Skip to main content

active_reporting/
mod.rs

1//^
2//^ HEAD
3//^
4
5//> HEAD -> DOCS
6#![doc = include_str!("README.md")]
7
8//> HEAD -> LINTS
9#![allow(incomplete_features)]
10
11//> HEAD -> FEATURES
12#![feature(const_trait_impl)]
13#![feature(unsized_const_params)]
14#![feature(adt_const_params)]
15#![feature(default_field_values)]
16#![feature(const_heap)]
17#![feature(const_default)]
18#![feature(never_type)]
19#![feature(generic_const_exprs)]
20
21//> HEAD -> MODULES
22mod state;
23#[cfg(test)]
24mod tests;
25
26//> HEAD -> PUBLIC STATE
27pub use state::{
28    Same,
29    Name
30};
31
32//> HEAD -> STATE
33use state::{
34    State,
35    Main,
36    DerivedState
37};
38
39//> HEAD -> ISSUING
40use issuing::Issue;
41
42//> HEAD -> SYSTEMSTD
43use systemstd::System;
44
45//> HEAD -> SYSTEMIO
46use systemio::{
47    SystemIO, 
48    Update
49};
50
51
52//^ 
53//^ REPORT
54//^ 
55
56//> REPORT -> STRUCT
57pub struct Report<Current: State> {
58    data: Current
59}
60
61//> REPORT -> MAIN IMPLEMENTATION
62impl Report<Main> {
63    pub const fn new(name: &'static str) -> Self {
64        let mut chain = Vec::new();
65        chain.push(name);
66        return Self {
67            data: Main {
68                chain: chain
69            }
70        };
71    }
72}
73
74//> REPORT -> IMPLEMENTATION
75impl<Current: const State> Report<Current> {
76    pub const fn to<'valid, Following: const DerivedState<'valid>>(&'valid mut self) -> Report<Following> {
77        return Report {
78            data: Following::convert(&mut self.data)
79        }
80    }
81    pub fn issue(&self, object: impl Into<Issue>) -> Option<!> {
82        System::problem(object.into(), self.data.get()).sync();
83        return None;
84    }
85    pub fn eat<Type>(&self, result: Result<Type, Issue>) -> Option<Type> {return match result {
86        Ok(value) => Some(value),
87        Err(issue) => self.issue(issue)?
88    }}
89}
90
91//> REPORT -> DEFAULT
92const impl Default for Report<Main> {
93    fn default() -> Self {return Self::new("Main")}
94}