pub enum Doc {
Nil,
Text(String),
Line,
SoftLine,
HardLine,
Indent(Box<Doc>),
Concat(Box<Doc>, Box<Doc>),
Group(Box<Doc>),
IfBreak {
flat: Box<Doc>,
broken: Box<Doc>,
},
}Expand description
Intermediate representation for formatting.
A Doc describes how content should be laid out, with the actual
line-breaking decisions deferred to the printer.
Variants§
Nil
Empty document
Text(String)
Literal text (no line breaks allowed within)
Line
A line break: becomes a single space if the enclosing group fits on one line, otherwise becomes a newline followed by current indentation.
SoftLine
A soft line break: becomes empty if the enclosing group fits on one line, otherwise becomes a newline followed by current indentation.
HardLine
Always a line break, regardless of whether the group fits.
Indent(Box<Doc>)
Increase indentation for the nested document.
Concat(Box<Doc>, Box<Doc>)
Concatenate two documents.
Group(Box<Doc>)
Try to fit the document on one line. If it doesn’t fit within the
max width, break at Line and SoftLine positions.
IfBreak
Conditional content based on whether the enclosing group breaks.
flat: used when the group fits on one linebroken: used when the group breaks across lines
Implementations§
Source§impl Doc
impl Doc
Sourcepub fn join(docs: impl IntoIterator<Item = Doc>, sep: Doc) -> Doc
pub fn join(docs: impl IntoIterator<Item = Doc>, sep: Doc) -> Doc
Join multiple documents with a separator.
Sourcepub fn concat_all(docs: impl IntoIterator<Item = Doc>) -> Doc
pub fn concat_all(docs: impl IntoIterator<Item = Doc>) -> Doc
Concatenate multiple documents.
Trait Implementations§
impl Eq for Doc
impl StructuralPartialEq for Doc
Auto Trait Implementations§
impl Freeze for Doc
impl RefUnwindSafe for Doc
impl Send for Doc
impl Sync for Doc
impl Unpin for Doc
impl UnsafeUnpin for Doc
impl UnwindSafe for Doc
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.