Pretty Printing

facet-pretty provides colorful, readable pretty-printing for any Facet type. But it can also print the shape itself — showing the structure of your types at compile time. Below we show each value alongside its shape.

Primitives: Integers

Simple numeric types show their value directly, and their shape reveals the underlying primitive type.

Value

42

Shape

Primitives: Floats

Floating-point numbers are displayed with their full precision.

Value

3.141592653589793

Shape

Primitives: Booleans

Boolean values are shown as `true` or `false`.

Value

true

Shape

Primitives: Characters

Character values are displayed with their Unicode representation.

Value

🦀

Shape

Primitives: Strings

String types show their content in quotes.

Value

"Hello, facet!"

Shape

Tuples: Pair

Tuples are displayed with their elements, and the shape shows each element's type.

Value

(f64, u32) (
  3.5,
  41,
)

Shape

#[derive(Facet)]
struct ()(f64, u32);

Tuples: Triple

Larger tuples work the same way — each element type is tracked.

Value

(&str, u32, bool) (
  "Alice",
  30,
  true,
)

Shape

#[derive(Facet)]
struct ()(&T, u32, bool);

Structs: Simple

Struct fields are displayed with their names and values. The shape shows field names, types, and offsets.

Value

Point {
  x1.5,
  y2.5,
}

Shape

#[derive(Facet)]
struct Point {
    x: f64,
<span style="color:#7aa2f7;">y</span><span style="color:#a9b1d6;">:</span> <span style="color:#2ac3de;">f64</span><span style="color:#a9b1d6;">,</span>

}

Structs: With Optional Fields

Optional fields show `Some(...)` or `None`. The shape includes the full Option type.

Value

Person {
  name"Alice",
  age30,
  emailOption::Some("alice@example.com"),
}

Shape

#[derive(Facet)]
struct Person {
    name: String,
<span style="color:#7aa2f7;">age</span><span style="color:#a9b1d6;">:</span> <span style="color:#2ac3de;">u32</span><span style="color:#a9b1d6;">,</span>

<span style="color:#7aa2f7;">email</span><span style="color:#a9b1d6;">:</span> <span style="color:#2ac3de;">Option</span><span style="color:#a9b1d6;">&lt;</span><span style="color:#2ac3de;">String</span><span style="color:#a9b1d6;">&gt;,</span>

}

Enums: Unit Variant

Unit variants display just the variant name. The shape shows all possible variants.

Value

Color::Blue

Shape

#[derive(Facet)]
#[repr(u8)]
enum Color {
    Red,
Green<span style="color:#a9b1d6;">,</span>

Blue<span style="color:#a9b1d6;">,</span>

Rgb<span style="color:#a9b1d6;">(</span><span style="color:#2ac3de;">u8</span><span style="color:#a9b1d6;">,</span> <span style="color:#2ac3de;">u8</span><span style="color:#a9b1d6;">,</span> <span style="color:#2ac3de;">u8</span><span style="color:#a9b1d6;">),</span>

}

Enums: Tuple Variant

Tuple variants show their contained values.

Value

Color::Rgb(
  255,
  128,
  0,
)

Shape

#[derive(Facet)]
#[repr(u8)]
enum Color {
    Red,
Green<span style="color:#a9b1d6;">,</span>

Blue<span style="color:#a9b1d6;">,</span>

Rgb<span style="color:#a9b1d6;">(</span><span style="color:#2ac3de;">u8</span><span style="color:#a9b1d6;">,</span> <span style="color:#2ac3de;">u8</span><span style="color:#a9b1d6;">,</span> <span style="color:#2ac3de;">u8</span><span style="color:#a9b1d6;">),</span>

}

Enums: Struct Variant

Struct variants display their field names and values.

Value

Message::Move {
  x10,
  y20,
}

Shape

#[derive(Facet)]
#[repr(u8)]
enum Message {
    Quit,
Move <span style="color:#a9b1d6;">{</span>
    <span style="color:#7aa2f7;">x</span><span style="color:#a9b1d6;">:</span> <span style="color:#2ac3de;">i32</span><span style="color:#a9b1d6;">,</span>

    <span style="color:#7aa2f7;">y</span><span style="color:#a9b1d6;">:</span> <span style="color:#2ac3de;">i32</span><span style="color:#a9b1d6;">,</span>
<span style="color:#a9b1d6;">},</span>

Write<span style="color:#a9b1d6;">(</span><span style="color:#2ac3de;">String</span><span style="color:#a9b1d6;">),</span>

}

Collections: Vec

Vectors show their elements in a list. The shape describes the element type.

Value

Vec<i32> [1, 2, 3, 4, 5]

Shape

Collections: Array

Fixed-size arrays show their elements. The shape includes the array length.

Value

[u8; 4] [
   0a 14 1e 28
]

Shape

Collections: HashMap

Maps display their key-value pairs. The shape describes both key and value types.

Value

HashMap<String, i32> [
  "two" => 2,
  "three" => 3,
  "one" => 1,
]

Shape

Option: Some

Option::Some displays its contained value.

Value

Option::Some("present")

Shape

Option: None

Option::None displays cleanly without the type clutter.

Value

Option::None

Shape

Result: Ok

Result::Ok displays its success value.

Value

unsupported peek variant: Ok(42)

Shape

Result: Err

Result::Err displays the error value.

Value

unsupported peek variant: Err("something went wrong")

Shape

Nested Structures

Complex nested types are pretty-printed with proper indentation. The shape shows the full type hierarchy.

Value

Company {
  name"Acme Corp",
  addressAddress {
    street"123 Main St",
    city"Springfield",
    zip"12345",
  },
  employeesVec<Person> [
    Person {
      name"Alice",
      age30,
      emailOption::Some("alice@acme.com"),
    },
    Person {
      name"Bob",
      age25,
      emailOption::None,
    },
  ],
}

Shape

#[derive(Facet)]
struct Company {
    name: String,
<span style="color:#7aa2f7;">address</span><span style="color:#a9b1d6;">:</span> <span style="color:#2ac3de;">Address</span><span style="color:#a9b1d6;">,</span>

<span style="color:#7aa2f7;">employees</span><span style="color:#a9b1d6;">:</span> <span style="color:#2ac3de;">Vec</span><span style="color:#a9b1d6;">&lt;</span><span style="color:#2ac3de;">Person</span><span style="color:#a9b1d6;">&gt;,</span>

}

#[derive(Facet)] struct Person { name: String,

<span style="color:#7aa2f7;">age</span><span style="color:#a9b1d6;">:</span> <span style="color:#2ac3de;">u32</span><span style="color:#a9b1d6;">,</span>

<span style="color:#7aa2f7;">email</span><span style="color:#a9b1d6;">:</span> <span style="color:#2ac3de;">Option</span><span style="color:#a9b1d6;">&lt;</span><span style="color:#2ac3de;">String</span><span style="color:#a9b1d6;">&gt;,</span>

}

#[derive(Facet)] struct Address { street: String,

<span style="color:#7aa2f7;">city</span><span style="color:#a9b1d6;">:</span> <span style="color:#2ac3de;">String</span><span style="color:#a9b1d6;">,</span>

<span style="color:#7aa2f7;">zip</span><span style="color:#a9b1d6;">:</span> <span style="color:#2ac3de;">String</span><span style="color:#a9b1d6;">,</span>

}