mod act;
mod machine;
mod shortcut;
use std::time::Instant;
use crate::{
problem::{
Problem,
Severity
},
issue::Issue
};
pub use act::Act;
pub use machine::{
Main,
Mode,
Set
};
pub struct Report<State: Mode>(State);
impl Default for Report<Main> {
fn default() -> Self {return Self(Main)}
}
impl<State: Mode> Report<State> {
#[inline]
pub fn warn<Object: Into<Issue>>(&self, object: Object) -> () {
self.0.send(Problem {
chain: Vec::new(),
at: Instant::now(),
object: object,
severity: Severity::Warning
});
}
#[inline]
pub fn error<Object: Into<Issue>>(&self, object: Object) -> () {
self.0.send(Problem {
chain: Vec::new(),
at: Instant::now(),
object: object,
severity: Severity::Error
});
}
#[inline]
pub fn sub<'valid, const NAME: &'static str>(&'valid self) -> Report<Set<'valid, NAME>> {return Report(self.0.connect())}
#[inline]
pub fn with<Type>(self, value: Type) -> Act<Type, {State::NAME}> {return Act(Some(value))}
#[inline]
pub fn with_default<Type: Default>(self) -> Act<Type, {State::NAME}> {return Act(Some(Type::default()))}
#[inline]
pub fn fail<Type, Object: Into<Issue>>(self, object: Object) -> Act<Type, {State::NAME}> {
self.0.send(Problem {
chain: Vec::new(),
at: Instant::now(),
object: object,
severity: Severity::Critical
});
return Act(None);
}
}