use crate::diagnostic::Diagnostic;
#[derive(Debug)]
pub struct TWithDiagnosticArray<T: std::fmt::Debug> {
pub inner: T,
pub diagnostic: Vec<Diagnostic>,
}
impl<T: std::fmt::Debug> TWithDiagnosticArray<T> {
pub fn new(inner: T, diagnostic: Vec<Diagnostic>) -> Self {
Self { inner, diagnostic }
}
pub fn diagnostics(&self) -> &Vec<Diagnostic> {
&self.diagnostic
}
pub fn split_into_parts(self) -> (T, Vec<Diagnostic>) {
(self.inner, self.diagnostic)
}
pub fn get(&self) -> &T {
&self.inner
}
}
impl<T: Clone + std::fmt::Debug> Clone for TWithDiagnosticArray<T> {
fn clone(&self) -> Self {
Self {
inner: self.inner.clone(),
diagnostic: self.diagnostic.clone(),
}
}
}
pub trait IntoTWithDiagnosticArray {
fn with_diagnostic(self, diagnostic: Vec<Diagnostic>) -> TWithDiagnosticArray<Self>
where
Self: Sized + std::fmt::Debug;
fn with_empty_diagnostic(self) -> TWithDiagnosticArray<Self>
where
Self: Sized + std::fmt::Debug,
{
TWithDiagnosticArray {
inner: self,
diagnostic: vec![],
}
}
}
impl<T: Sized + std::fmt::Debug> IntoTWithDiagnosticArray for T {
fn with_diagnostic(self, diagnostic: Vec<Diagnostic>) -> TWithDiagnosticArray<Self>
where
Self: Sized + std::fmt::Debug,
{
TWithDiagnosticArray {
inner: self,
diagnostic,
}
}
}