#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq)]
pub struct DisplayAsDebugWrapper<T>(pub T);
pub trait AstToStrExt {
fn with_display_as_debug_wrapper(&self) -> DisplayAsDebugWrapper<&'_ Self>
where
Self: std::fmt::Display,
{
DisplayAsDebugWrapper(self)
}
}
impl AstToStrExt for String {}
impl AstToStrExt for str {}
impl<'a> AstToStrExt for std::borrow::Cow<'a, str> {}
impl<T: std::fmt::Display> crate::AstToStr for DisplayAsDebugWrapper<T> {
fn ast_to_str_impl(&self, _: &dyn crate::Symbols) -> String {
format!("{:?}", self)
}
}
impl<T> std::fmt::Debug for DisplayAsDebugWrapper<T>
where
T: std::fmt::Display,
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}
impl<T> std::ops::Deref for DisplayAsDebugWrapper<T> {
type Target = T;
fn deref(&self) -> &Self::Target {
&self.0
}
}