use super::*;
use static_assertions::assert_obj_safe;
use std::fmt::Debug;
assert_obj_safe!(Diag);
pub trait Diag: Debug + Send + Sync {
fn severity(&self) -> Severity;
fn build(&self, builder: Builder) -> Builder;
}
pub type Result<'d, T> = std::result::Result<T, DiagBox<'d>>;
pub struct DiagBox<'d>(Box<dyn Diag + Send + Sync + 'd>);
impl std::fmt::Debug for DiagBox<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.0.fmt(f)
}
}
impl<'d, E> From<E> for DiagBox<'d>
where
E: Diag + 'd,
{
fn from(value: E) -> Self {
DiagBox(Box::new(value))
}
}
impl<'d> std::ops::Deref for DiagBox<'d> {
type Target = Box<dyn Diag + Send + Sync + 'd>;
fn deref(&self) -> &Self::Target {
&self.0
}
}