dbgfmt 0.3.0

Pretty-print Rust Debug trait output with proper indentation
Documentation
  • Coverage
  • 0%
    0 out of 3 items documented0 out of 2 items with examples
  • Size
  • Source code size: 95.16 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.61 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 58s Average build duration of successful builds.
  • all releases: 52s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • poi2/dbgfmt
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • poi2

dbgfmt

CI crates.io License: MIT OR Apache-2.0

A zero-dependency Rust library and CLI tool that pretty-prints Rust Debug trait output with proper indentation and newlines.

Example

Input:

Foo { bar: 1, baz: Vec { items: [1, 2, 3] }, name: "hello" }

Output:

Foo {
    bar: 1,
    baz: Vec {
        items: [
            1,
            2,
            3,
        ],
    },
    name: "hello",
}

As a Library

Add to your Cargo.toml:

[dependencies]
dbgfmt = "0.1"

Use in your code:

use dbgfmt::format_debug;

let input = format!("{:?}", my_struct);
let pretty = format_debug(&input, 4);
println!("{pretty}");

As a CLI

Installation

Homebrew

brew install poi2/tap/dbgfmt

Shell script

curl --proto '=https' --tlsv1.2 -LsSf https://github.com/poi2/dbgfmt/releases/latest/download/dbgfmt-installer.sh | sh

Cargo

cargo install dbgfmt

Usage

# Pass as argument
dbgfmt 'Foo { bar: 1, baz: [2, 3] }'

# Pipe from stdin
echo 'Foo { bar: 1, baz: [2, 3] }' | dbgfmt

# Format dbg!() macro output (prefix is preserved)
echo '[src/main.rs:5:5] config = Config { host: "localhost", port: 8080 }' | dbgfmt

# Multiple values (separate lines or same line)
printf 'Foo { x: 1 }\nBar { y: 2 }' | dbgfmt

# Best-effort format broken/truncated input
dbgfmt --recover 'Foo { bar: 1, baz: Bar { x:'

License

Licensed under either of

at your option.