use std::{borrow::Cow, error::Error}; use miette::Diagnostic; use crate::miette_helpers::{WithHelp, WithLabel}; /// Useful to convert [std::error::Error] to [crate::DiagnosticError] pub trait ErrorExt { fn boxed(self) -> Box; } impl ErrorExt for T { fn boxed(self) -> Box { Box::new(self) } } pub trait DiagnosticExt { fn boxed(self) -> Box; } impl DiagnosticExt for T { fn boxed(self) -> Box { Box::new(self) } } pub trait MietteExt { fn with_help(self, message: impl Into>) -> Box; fn with_labels( self, labels: impl Iterator, ) -> Box; } impl MietteExt for Box { fn with_help(self, message: impl Into>) -> Box { let h = WithHelp::from(self).with_help(message); ::boxed(h) } fn with_labels( self, labels: impl Iterator, ) -> Box { let l = WithLabel::from(self).with_label(labels); ::boxed(l) } } impl MietteExt for miette::Error { fn with_help(self, message: impl Into>) -> Box { let h = WithHelp::from(self).with_help(message); ::boxed(h) } fn with_labels( self, labels: impl Iterator, ) -> Box { let l = WithLabel::from(self).with_label(labels); ::boxed(l) } }