# dbgfmt
[](https://github.com/poi2/dbgfmt/actions/workflows/ci.yml)
[](https://crates.io/crates/dbgfmt)
[](LICENSE-MIT)
A zero-dependency Rust library and CLI tool that pretty-prints Rust `Debug` trait output with proper indentation and newlines.
## Example
**Input:**
```text
Foo { bar: 1, baz: Vec { items: [1, 2, 3] }, name: "hello" }
```
**Output:**
```text
Foo {
bar: 1,
baz: Vec {
items: [
1,
2,
3,
],
},
name: "hello",
}
```
## As a Library
Add to your `Cargo.toml`:
```toml
[dependencies]
dbgfmt = "0.1"
```
Use in your code:
```rust
use dbgfmt::format_debug;
let input = format!("{:?}", my_struct);
let pretty = format_debug(&input, 4);
println!("{pretty}");
```
## As a CLI
### Installation
#### Homebrew
```bash
brew install poi2/tap/dbgfmt
```
#### Shell script
```bash
#### Cargo
```bash
cargo install dbgfmt
```
### Usage
```bash
# Pass as argument
dbgfmt 'Foo { bar: 1, baz: [2, 3] }'
# Pipe from stdin
# Format dbg!() macro output (prefix is preserved)
# 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
- [Apache License, Version 2.0](LICENSE-APACHE)
- [MIT License](LICENSE-MIT)
at your option.