#![allow(incomplete_features)]
#![feature(const_trait_impl)]
#![feature(unsized_const_params)]
#![feature(adt_const_params)]
#![feature(default_field_values)]
#![feature(const_heap)]
#![feature(never_type)]
#![feature(const_default)]
#![feature(generic_const_exprs)]
mod state;
#[cfg(test)]
mod tests;
mod then;
pub use state::{
Same,
Name
};
use state::{
State,
Main,
DerivedState
};
use libutils_issue::Issue;
use libutils_terminal::TERMINAL;
use libutils_threat::Threat;
use libutils_console::{
Console,
Synchronization
};
use then::Then;
pub struct Report<Current: State> {
data: Current
}
impl Report<Main> {
pub const fn new(name: &'static str) -> Self {
let mut chain = Vec::new();
chain.push(name);
return Self {
data: Main {
chain: chain
}
};
}
}
const impl Default for Report<Main> {
fn default() -> Self {return Self::new("Main")}
}
impl<Current: State> Report<Current> {
pub fn to<'valid, Following: DerivedState<'valid>>(&'valid mut self) -> Report<Following> {return Report {
data: Following::convert(&mut self.data)
}}
pub fn issue(&self, object: impl Into<Issue>) -> Then<!> {
TERMINAL.problem(Threat {
issue: object.into(),
chain: self.data.chain()
}).sync();
return Then {
value: None
};
}
pub fn apply<Type>(&self, result: Result<Type, impl Into<Issue>>) -> Then<Type> {return Then {
value: match result {
Ok(value) => Some(value),
Err(issue) => self.issue(issue).none()
}
}}
}