mod act;
mod issue;
mod note;
mod shortcut;
mod toissue;
use std::time::Instant;
pub use toissue::ToIssue;
pub use issue::Issue;
use crate::terminal::{
TERMINAL,
Problem,
Console,
Severity
};
pub use note::Note;
pub use act::Act;
pub struct Report<Object: ToIssue, const NAME: &'static str> {
problems: Vec<Problem<Object>> = Vec::new()
}
impl<Object: ToIssue, const NAME: &'static str> Default for Report<Object, NAME> {
fn default() -> Self {return Self {..}}
}
impl<Object: ToIssue, const NAME: &'static str> Report<Object, NAME> {
#[inline]
pub fn warn(&mut self, object: Object) -> () {
let problem = Problem {
chain: Vec::from([NAME]),
at: Instant::now(),
object: object,
severity: Severity::Warning
};
TERMINAL.write().issue(&problem);
self.problems.push(problem);
}
#[inline]
pub fn error(&mut self, object: Object) -> () {
let problem = Problem {
chain: Vec::from([NAME]),
at: Instant::now(),
object: object,
severity: Severity::Error
};
TERMINAL.write().issue(&problem);
self.problems.push(problem);
}
#[inline]
pub fn finish<Type>(mut self, with: Result<Type, Object>) -> Act<Type, Object, NAME> {return match with {
Ok(value) => Act {
problems: self.problems,
result: Some(value)
},
Err(object) => {
let problem = Problem {
chain: Vec::from([NAME]),
at: Instant::now(),
object: object,
severity: Severity::Critical
};
TERMINAL.write().issue(&problem);
self.problems.push(problem);
Act {
problems: self.problems,
result: None
}
}
}}
}