pprint

A Rust library for pretty ✨ printing using a document model. Automatically derive Pretty for structs, enums, and primitive types; vector and map types are also supported by default; very similar to the derive(Debug) macro, just prettier and more configurable.

Usage

```rust use pprint::{Doc, Printer, PRINTER};

let doc = Doc::from(vec![1, 2, 3]) .wrap("[", "]") .join(", ");

print!("{}", PRINTER.pretty(doc)); // prints: // [ // 1, // 2, // 3 // ] ```

Document Model

The document model provides a rich set of building blocks:

The Printer handles pretty printing a Doc to a string with configurable options:

Derive Macro

Half of the library's development time was spent on the derive macro, allowing for easy pretty printing of essentially any type. Here's a trivial example:

```rust

[derive(Pretty)]

struct Point { x: f64, y: f64 }

let point = Point { x: 1.0, y: 2.0 }; print!("{}", Doc::from(point)); // prints "(x: 1, y: 2)" ```

Pretty supports an additional attribute, pprint, which is used to customize an object's pretty printing definition. The following options are available:

```rust

[derive(Pretty)]

[pprint(verbose)]

struct Point { #[pprint(rename = "x-coordinate")] x: f64, #[pprint(rename = "y-coordinate")] y: f64 #[pprint(skip)] skipme: bool, }

let point = Point { x: 1.0, y: 2.0, skipme: true }; print!("{}", Doc::from(point)); // prints: // Point { // x-coordinate: 1, // y-coordinate: 2 // } ```

Structures can be arbitrarily nested, & c. & c. More involved examples can be found in the tests file.