mod act;
mod shortcut;
use std::time::Instant;
use crate::{
problem::{
Problem,
Severity
},
issue::Issue,
terminal::{
TERMINAL,
Console
},
array::Array
};
pub use act::Act;
use core::mem::transmute_neo as transmute;
pub struct Report<const NAME: &'static str, const N: usize> {
chain: Array<&'static str, N>
}
impl const Default for Report<"Main", 1> {
fn default() -> Self {
let mut chain = Array::default();
chain.push("Main");
return Self {
chain: chain
}
}
}
impl<const NAME: &'static str, const N: usize> Report<NAME, N> {
#[inline]
fn send<Object: Into<Issue>>(&self, mut problem: Problem<Object>) -> () {
problem.chain = self.chain.clone().into_iter().collect();
TERMINAL.write().issue(problem);
}
#[inline]
pub fn warn<Object: Into<Issue>>(&self, object: Object) -> () {self.send(Problem {
chain: Vec::new(),
at: Instant::now(),
object: object,
severity: Severity::Warning
})}
#[inline]
pub fn error<Object: Into<Issue>>(&self, object: Object) -> () {self.send(Problem {
chain: Vec::new(),
at: Instant::now(),
object: object,
severity: Severity::Error
})}
#[inline]
pub fn sub<'valid, const OTHER: &'static str>(&'valid self) -> Report<OTHER, {N + 1}> {
let mut chain = Array::from_iter(self.chain.clone().into_iter());
chain.push(OTHER);
return Report {
chain: chain
}
}
#[inline]
pub fn with<Type>(self, value: Type) -> Act<Type> {return unsafe {transmute(Some(value))}}
#[inline]
pub fn with_default<Type: Default>(self) -> Act<Type> {return unsafe {transmute(Some(Type::default()))}}
#[inline]
pub fn fail<Type, Object: Into<Issue>>(self, object: Object) -> Act<Type> {
self.send(Problem {
chain: Vec::new(),
at: Instant::now(),
object: object,
severity: Severity::Critical
});
return unsafe {transmute(None::<Type>)};
}
}