#![allow(incomplete_features)]
#![feature(const_trait_impl)]
#![feature(unsized_const_params)]
#![feature(adt_const_params)]
#![feature(default_field_values)]
#![feature(const_heap)]
#![feature(const_default)]
#![feature(generic_const_exprs)]
mod state;
#[cfg(test)]
mod tests;
pub use state::{
Same,
Name
};
use state::{
State,
Main,
DerivedState
};
use libutils_issue::Issue;
use libutils_terminal::{
Console,
TERMINAL
};
use libutils_threat::Threat;
use libutils_cage::Cage;
pub struct Report<Current: State> {
data: Current,
cage: &'static Cage<dyn Console>
}
impl Report<Main> {
pub const fn new(name: &'static str) -> Self {return Self::with(name, &TERMINAL)}
pub const fn with(name: &'static str, cage: &'static Cage<dyn Console>) -> Self {
let mut chain = Vec::new();
chain.push(name);
return Self {
data: Main {
chain: chain,
},
cage: cage
};
}
}
const impl Default for Report<Main> {
fn default() -> Self {return Self::new("Main")}
}
impl<Current: State> Report<Current> {
#[inline]
pub fn to<'valid, Following: DerivedState<'valid>>(&'valid mut self) -> Report<Following> {return Report {
data: Following::from(&mut self.data),
cage: self.cage
}}
#[inline]
pub fn issue<Object: Into<Issue>, Type>(&self, object: Object) -> Option<Type> {
let mut console = self.cage.write();
console.problem(Threat {
issue: object.into(),
chain: self.data.chain()
});
console.sync();
return None;
}
}