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