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(never_type)]
13#![feature(const_default)]
14#![feature(generic_const_exprs)]
15
16mod state;
18#[cfg(test)]
19mod tests;
20mod then;
21
22pub use state::{
24 Same,
25 Name
26};
27
28use state::{
30 State,
31 Main,
32 DerivedState
33};
34
35use libutils_issue::Issue;
37
38use libutils_terminal::TERMINAL;
40
41use libutils_threat::Threat;
43
44use libutils_console::{
46 Console,
47 Synchronization
48};
49
50use then::Then;
52
53
54pub struct Report<Current: State> {
60 data: Current
61}
62
63impl 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
76const impl Default for Report<Main> {
78 fn default() -> Self {return Self::new("Main")}
79}
80
81impl<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}