#pretty-print #formatting #reflection #serialization

shapely-pretty

Pretty-printing for types implementing the Shapely trait

1 stable release

Uses new Rust 2024

new 3.0.0 Mar 11, 2025

#49 in Visualization

MIT/Apache

105KB
2K SLoC

shapely-pretty

experimental free of syn crates.io documentation MIT/Apache-2.0 licensed

[!IMPORTANT]

There is no stable shapely API as of now (even though it's >1.0.0). The design is very much still being explored.

Expect multiple major versions in the near future — (note left 2025-03-11)

A pretty-printing library for types implementing the Shapely trait, providing colorful and well-formatted output.

Features

  • Pretty-print any type implementing the Shapely trait
  • Colorful output with ANSI escape codes
  • Unique colors for different scalar types based on their Shape hash
  • Customizable indentation and formatting
  • Dimmed colors for punctuation
  • Simple abstraction over ANSI escape codes

Example

use shapely::Shapely;
use shapely_pretty::PrettyPrinter;

#[derive(Debug, Shapely)]
struct Person {
    name: String,
    age: u32,
    address: Address,
}

#[derive(Debug, Shapely)]
struct Address {
    street: String,
    city: String,
    country: String,
}

let person = Person {
    name: "Alice".to_string(),
    age: 30,
    address: Address {
        street: "123 Main St".to_string(),
        city: "Wonderland".to_string(),
        country: "Imagination".to_string(),
    },
};

// Print with default settings
PrettyPrinter::new().print(&person);

// Customize the printer
PrettyPrinter::new()
    .with_indent_size(4)
    .with_max_depth(3)
    .print(&person);

License

Licensed under either of:

at your option.

Dependencies