Add `PrettyPrinter::print` convenience method
Closes: #165 Approved by: whitequark
This commit is contained in:
parent
1097ba3110
commit
ec4c48af6c
|
@ -93,6 +93,17 @@ impl<'a, T: PrettyPrint> PrettyPrinter<'a, T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, T: PrettyPrint + AsRef<[u8]>> PrettyPrinter<'a, T> {
|
||||
/// Create a `PrettyPrinter` which prints the given object.
|
||||
pub fn print(printable: &'a T) -> PrettyPrinter<'a, T> {
|
||||
PrettyPrinter {
|
||||
prefix: "",
|
||||
buffer: printable,
|
||||
phantom: PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T: PrettyPrint> fmt::Display for PrettyPrinter<'a, T> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
T::pretty_print(&self.buffer, f, &mut PrettyIndent::new(self.prefix))
|
||||
|
|
Loading…
Reference in New Issue