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(never_type)]
14#![feature(generic_const_exprs)]
15
16mod state;
18#[cfg(test)]
19mod tests;
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
49
50pub struct Report<Current: State> {
56 data: Current
57}
58
59impl Report<Main> {
61 pub const fn new(name: &'static str) -> Self {
62 let mut chain = Vec::new();
63 chain.push(name);
64 return Self {
65 data: Main {
66 chain: chain
67 }
68 };
69 }
70}
71
72const impl Default for Report<Main> {
74 fn default() -> Self {return Self::new("Main")}
75}
76
77impl<Current: State> Report<Current> {
79 pub fn to<'valid, Following: DerivedState<'valid>>(&'valid mut self) -> Report<Following> {return Report {
80 data: Following::convert(&mut self.data)
81 }}
82 pub fn issue(&self, object: impl Into<Issue>) -> Option<!> {
83 TERMINAL.problem(Threat {
84 issue: object.into(),
85 chain: self.data.chain()
86 }).sync();
87 return None;
88 }
89 pub fn eat<Type>(&self, result: Result<Type, Issue>) -> Option<Type> {return match result {
90 Ok(value) => Some(value),
91 Err(issue) => self.issue(issue)?
92 }}
93}