Expand description
A Wadler-Lindig pretty-printing engine.
Build a Doc tree that describes the structure of your output, then let
the printer decide where to break lines based on the available width. The
core idea: group marks a subtree as a flat/break decision boundary — the
printer tries to render it on one line and falls back to multi-line only when
the content would exceed FormatOptions::print_width.
§Quick start
use rlsp_fmt::{Doc, concat, group, indent, line, text, format, FormatOptions};
// Build a document: "[" <items> "]"
let doc = group(concat(vec![
text("["),
indent(concat(vec![line(), text("a"), text(","), line(), text("b")])),
line(),
text("]"),
]));
let opts = FormatOptions { print_width: 80, ..Default::default() };
assert_eq!(format(&doc, &opts), "[ a, b ]");
// Narrow width forces the group to break.
let opts_narrow = FormatOptions { print_width: 5, ..Default::default() };
assert!(format(&doc, &opts_narrow).contains('\n'));See FormatOptions for all rendering controls.
Re-exports§
pub use ir::Doc;pub use ir::concat;pub use ir::flat_alt;pub use ir::group;pub use ir::hard_line;pub use ir::indent;pub use ir::join;pub use ir::line;pub use ir::text;pub use printer::format;
Modules§
- ir
- Intermediate representation types for the pretty-printing engine.
- printer
- The Wadler-Lindig line-breaking printer.
Structs§
- Format
Options - Options that control how a document is rendered.