prettyplease
A minimal syn syntax tree pretty-printer for formatting generated Rust code.
Repository Health
Technical Analysis
prettyplease is a minimal pretty-printer that turns a syn syntax tree into a String of well-formatted Rust source code. Unlike rustfmt, which prioritizes impeccable output using heavyweight algorithms that can bail out on hard-to-format code, prettyplease is designed to be robust and suitable for arbitrary generated code.
Its single-purpose unparse function makes it the go-to formatting layer for procedural macros, code generators, and build scripts that emit Rust and want readable output without shelling out to an external rustfmt binary.
What You Get
- A single
unparseentry point that formats asyn::Fileinto a String - Robust formatting that does not bail out on unusual generated code
- In-process operation with no dependency on an external rustfmt binary
- Deterministic, readable output well suited to code generators and macros
Common Use Cases
- Formatting Rust source emitted by procedural macros or build scripts
- Producing readable output from code generators and bindings tools
- Formatting generated code where invoking rustfmt is impractical
Under The Hood
Architecture - The crate mirrors syn’s node taxonomy with one module per construct — expr.rs, item.rs, stmt.rs, pat.rs, ty.rs, generics.rs, attr.rs, lit.rs, mac.rs, path.rs and more — each knowing how to print its node. At the core, algorithm.rs and ring.rs implement the classic Oppen-style pretty-printing algorithm (a ring buffer of tokens with break/box logic), while convenience.rs, fixup.rs, classify.rs, and precedence.rs handle spacing, parenthesization, and correctness details. lib.rs exposes the top-level unparse.
Tech Stack - Rust built with Cargo. Its primary dependencies are syn (for the syntax tree it consumes) and proc-macro2; the printing algorithm itself is dependency-light and self-contained.
Code Quality - The implementation is carefully structured and battle-tested through extremely wide ecosystem usage (hundreds of millions of downloads). Modules like fixup.rs and precedence.rs show attention to subtle correctness (operator precedence, needed parentheses), and the code adheres to dtolnay’s consistently high crate conventions.
API Design - The public API is a single unparse(&syn::File) -> String, which is about as minimal and discoverable as possible. There is no configuration to learn and no boilerplate; anyone with a syn tree can format it in one line.
Used by 2 apps in this directory
Anarlog
Note Taking · AI Assistants · Productivity
Anarlog is an open-source, local-first AI meeting notetaker that records, transcribes, and summarizes meetings entirely on your device — no cloud lock-in, no mandatory account, and every note saved as a plain markdown file you own forever.
Qdrant
Databases · AI Development · Search
Open-source vector database and search engine built in Rust for production-grade AI applications — from semantic search to RAG pipelines and recommendation systems.