diff --git a/src/args.rs b/src/args.rs index 2028821..6c6497a 100644 --- a/src/args.rs +++ b/src/args.rs @@ -48,6 +48,13 @@ impl Arguments for Str { } } +macro_rules! not_for_pointer { + (Pointer $($tt:tt)*) => {}; + ($_not_pointer:ident $($tt:tt)*) => { + $($tt)* + } +} + macro_rules! traits { ($(struct $name:ident: trait $trait:ident);* $(;)?) => { $( @@ -66,6 +73,24 @@ macro_rules! traits { } )* + $( + not_for_pointer! { + $trait + + impl $trait for &T { + fn fmt(&self, f: &mut Formatter) -> Result { + ::fmt(&self, f) + } + } + + impl $trait for &mut T { + fn fmt(&self, f: &mut Formatter) -> Result { + ::fmt(&self, f) + } + } + } + )* + pub mod macro_exports { pub use super::{$($name, $trait),*}; } diff --git a/src/lib.rs b/src/lib.rs index f3525e6..b97fd32 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -33,28 +33,6 @@ pub trait Write { } } -impl Write for String { - fn write_str(&mut self, str: &str) -> Result { - self.push_str(str); - Ok(()) - } - - fn write_char(&mut self, char: char) -> Result { - self.push(char); - Ok(()) - } -} - -impl Write for &mut W { - fn write_str(&mut self, str: &str) -> Result { - ::write_str(self, str) - } - - fn write_char(&mut self, char: char) -> Result { - ::write_char(self, char) - } -} - pub mod helpers { use crate::{Arguments, Formatter, Result, Write}; diff --git a/src/rust_core_impl/aggregated.rs b/src/rust_core_impl/aggregated.rs index 01ba656..0c93f8c 100644 --- a/src/rust_core_impl/aggregated.rs +++ b/src/rust_core_impl/aggregated.rs @@ -6,12 +6,6 @@ mod impl_prelude { pub use crate::*; } -impl Debug for &T { - fn fmt(&self, f: &mut Formatter) -> Result { - ::fmt(&self, f) - } -} - impl Debug for [T; N] { fn fmt(&self, f: &mut Formatter) -> Result { <[T] as Debug>::fmt(&&self[..], f) @@ -96,3 +90,35 @@ mod char { } } } + +mod strings { + use super::impl_prelude::*; + + impl Display for String { + fn fmt(&self, f: &mut Formatter) -> Result { + f.write_str(self) + } + } + + impl Display for str { + fn fmt(&self, f: &mut Formatter) -> Result { + f.write_str(self) + } + } + + impl Debug for str { + fn fmt(&self, f: &mut Formatter) -> Result { + f.write_char('"')?; + f.write_str(self)?; + f.write_char('"') + } + } + + impl Debug for String { + fn fmt(&self, f: &mut Formatter) -> Result { + f.write_char('"')?; + f.write_str(self)?; + f.write_char('"') + } + } +} diff --git a/src/write.rs b/src/write.rs index 5650547..55b0345 100644 --- a/src/write.rs +++ b/src/write.rs @@ -1,29 +1,23 @@ -use crate::{Debug, Display, FmtOpts, Formatter, Result, Write}; +use crate::{Result, Write}; -impl Debug for &'_ str { - fn fmt(&self, f: &mut Formatter) -> Result { - f.write_char('"')?; - f.write_str(self)?; - f.write_char('"') +impl Write for String { + fn write_str(&mut self, str: &str) -> Result { + self.push_str(str); + Ok(()) + } + + fn write_char(&mut self, char: char) -> Result { + self.push(char); + Ok(()) } } -impl Display for &'_ str { - fn fmt(&self, f: &mut Formatter) -> Result { - f.write_str(self) +impl Write for &mut W { + fn write_str(&mut self, str: &str) -> Result { + ::write_str(self, str) } -} -impl Debug for String { - fn fmt(&self, f: &mut Formatter) -> Result { - f.write_char('"')?; - f.write_str(self)?; - f.write_char('"') - } -} - -impl Display for String { - fn fmt(&self, f: &mut Formatter) -> Result { - f.write_str(self) + fn write_char(&mut self, char: char) -> Result { + ::write_char(self, char) } }