pub struct Document { /* private fields */ }Expand description
One pretty-printed document: the owner of its layout options, its content, and its rendering.
Configure the layout with the builder methods (before anything is
printed), write content through printer, and
render by consuming the document with finish —
rendering happens exactly once, at the end. The PrettyPrinter this
hands out is write-only, so code that is given a printer (a
PrettyPrintable implementation, a
PrintableGenerator) can never render or
otherwise observe the document it is contributing to.
§Example
use hegel::Document;
let mut doc = Document::new().max_width(10);
let p = doc.printer();
p.begin_group(1, "[");
p.text("first");
p.text(",");
p.breakable(" ");
p.text("second");
p.end_group("]");
assert_eq!(doc.finish(), "[first,\n second]");Implementations§
Source§impl Document
impl Document
Sourcepub fn new() -> Self
pub fn new() -> Self
Create an empty document with the default layout options (a maximum line width of 79 characters).
Sourcepub fn max_width(self, max_width: usize) -> Self
pub fn max_width(self, max_width: usize) -> Self
Keep lines within max_width characters where the group structure
allows it. Defaults to 79.
Layout options describe the whole document, so they must be chosen
up front: calling this after printer has been
used is an error, as is a max_width of 0.
Sourcepub fn printer(&mut self) -> &mut PrettyPrinter
pub fn printer(&mut self) -> &mut PrettyPrinter
The printer to write this document’s content through.