pub fn full<C: Cost>(d: Doc<C>) -> Doc<C>Expand description
Requires that a document not be followed by any more text on the same line.
If more text is placed after this document without moving to a new line, the document will fail to render. Note that this doesn’t introduce the new line on its own. Instead, it forces the printer to choose paths that will uphold the constraint.
A typical use-case for this is line comments, where additional code cannot
be placed after the comment without becoming part of the comment text. By
wrapping the comment text in full, you ensure that the printer will not
produce a layout that changes the meaning of the document by placing code
tokens on the comment line.
§Example
let comment = full(text(";; this comment can't have code after it"));
let code = text("(print 123)");
let doc = comment.clone() & nl() & code.clone();
assert_eq!(doc.to_string(),
r";; this comment can't have code after it
(print 123)");
let doc = comment.clone() & code.clone();
assert!(matches!(doc.validate(80), Err(pretty_expressive::Error)));
// text afterwards is allowed if it is zero-length
let doc = comment.clone() & text("");
assert_eq!(
doc.to_string(),
";; this comment can't have code after it"
);