2019-07-24 00:22:11 +02:00
|
|
|
use crate::prelude::*;
|
|
|
|
use std::fmt;
|
|
|
|
|
|
|
|
pub struct Debuggable<'a, T: ToDebug> {
|
|
|
|
inner: &'a T,
|
|
|
|
source: &'a str,
|
|
|
|
}
|
|
|
|
|
2019-08-29 14:16:11 +02:00
|
|
|
impl<T: ToDebug> fmt::Display for Debuggable<'_, T> {
|
2019-07-24 00:22:11 +02:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
self.inner.fmt_debug(f, self.source)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-11 09:53:05 +02:00
|
|
|
pub trait HasSpan {
|
|
|
|
fn span(&self) -> Span;
|
2019-07-24 00:22:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
pub trait ToDebug: Sized {
|
2019-08-29 14:16:11 +02:00
|
|
|
fn debug<'a>(&'a self, source: &'a str) -> Debuggable<'a, Self> {
|
2019-07-24 00:22:11 +02:00
|
|
|
Debuggable {
|
|
|
|
inner: self,
|
|
|
|
source,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn fmt_debug(&self, f: &mut fmt::Formatter, source: &str) -> fmt::Result;
|
|
|
|
}
|