use std::error::Error;
#[derive(Debug, Default)]
pub(crate) struct DiagnosticCollector {
last_error: Option<Box<dyn Error + Send + Sync>>,
}
impl DiagnosticCollector {
#[allow(unused)]
pub(crate) fn report_error(&mut self, err: impl Into<Box<dyn Error + Send + Sync>>) {
self.last_error = Some(err.into());
}
#[allow(unused)]
pub(crate) fn capture<T, E: Into<Box<dyn Error + Send + Sync>>>(
&mut self,
err: Result<T, E>,
) -> Option<T> {
match err {
Ok(res) => Some(res),
Err(e) => {
self.report_error(e);
None
}
}
}
pub(crate) fn take_last_error(&mut self) -> Option<Box<dyn Error + Send + Sync>> {
self.last_error.take()
}
pub(crate) fn new() -> Self {
Self { last_error: None }
}
}