Forward Debug and Display for newtype wrappers
diff --git a/src/lib.rs b/src/lib.rs
index 269cf73..d019555 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -20,10 +20,12 @@
#[cfg(feature = "unstable")]
mod imp;
-#[derive(Clone, Debug)]
+#[macro_use]
+mod macros;
+
+#[derive(Clone)]
pub struct TokenStream(imp::TokenStream);
-#[derive(Debug)]
pub struct LexError(imp::LexError);
impl FromStr for TokenStream {
@@ -37,12 +39,6 @@
}
}
-impl fmt::Display for TokenStream {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- self.0.fmt(f)
- }
-}
-
impl From<proc_macro::TokenStream> for TokenStream {
fn from(inner: proc_macro::TokenStream) -> TokenStream {
TokenStream(inner.into())
@@ -86,7 +82,7 @@
}
}
-#[derive(Copy, Clone, Debug)]
+#[derive(Copy, Clone)]
pub struct Span(imp::Span);
impl Default for Span {
@@ -129,7 +125,7 @@
None,
}
-#[derive(Copy, Clone, Debug)]
+#[derive(Copy, Clone)]
pub struct Symbol(imp::Symbol);
impl<'a> From<&'a str> for Symbol {
@@ -156,15 +152,9 @@
Joint,
}
-#[derive(Clone, Debug)]
+#[derive(Clone)]
pub struct Literal(imp::Literal);
-impl fmt::Display for Literal {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- self.0.fmt(f)
- }
-}
-
impl Literal {
pub fn byte_char(b: u8) -> Literal {
Literal(imp::Literal::byte_char(b))
@@ -211,7 +201,6 @@
f32, f64, char, &'a str,
}
-#[derive(Debug)]
pub struct TokenIter(imp::TokenIter);
impl Iterator for TokenIter {
@@ -221,3 +210,12 @@
self.0.next()
}
}
+
+forward_fmt!(Debug for LexError);
+forward_fmt!(Debug for Literal);
+forward_fmt!(Debug for Span);
+forward_fmt!(Debug for Symbol);
+forward_fmt!(Debug for TokenIter);
+forward_fmt!(Debug for TokenStream);
+forward_fmt!(Display for Literal);
+forward_fmt!(Display for TokenStream);
diff --git a/src/macros.rs b/src/macros.rs
new file mode 100644
index 0000000..89eb554
--- /dev/null
+++ b/src/macros.rs
@@ -0,0 +1,9 @@
+macro_rules! forward_fmt {
+ ($tr:ident for $ty:ident) => {
+ impl ::std::fmt::$tr for $ty {
+ fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
+ ::std::fmt::$tr::fmt(&self.0, f)
+ }
+ }
+ }
+}