pub enum Doc<'a, T, A = ()> {
Nil,
Append(T, T),
Group(T),
Nest(usize, T),
Space,
Newline,
Text(Cow<'a, str>),
Annotated(A, T),
}
Expand description
The concrete document type. This type is not meant to be used directly. Instead use the static
functions on Doc
or the methods on an DocAllocator
.
The T
parameter is used to abstract over pointers to Doc
. See RefDoc
and BoxDoc
for how
it is used
Variants§
Implementations§
Source§impl<'a, T, A> Doc<'a, T, A>
impl<'a, T, A> Doc<'a, T, A>
Source§impl<'a, A> Doc<'a, BoxDoc<'a, A>, A>
impl<'a, A> Doc<'a, BoxDoc<'a, A>, A>
Sourcepub fn append<D>(self, that: D) -> Doc<'a, BoxDoc<'a, A>, A>
pub fn append<D>(self, that: D) -> Doc<'a, BoxDoc<'a, A>, A>
Append the given document after this document.
Sourcepub fn concat<I>(docs: I) -> Doc<'a, BoxDoc<'a, A>, A>
pub fn concat<I>(docs: I) -> Doc<'a, BoxDoc<'a, A>, A>
A single document concatenating all the given documents.
Sourcepub fn intersperse<I, S>(docs: I, separator: S) -> Doc<'a, BoxDoc<'a, A>, A>
pub fn intersperse<I, S>(docs: I, separator: S) -> Doc<'a, BoxDoc<'a, A>, A>
A single document interspersing the given separator S
between the given documents. For
example, if the documents are [A, B, C, ..., Z]
, this yields [A, S, B, S, C, S, ..., S, Z]
.
Sourcepub fn group(self) -> Doc<'a, BoxDoc<'a, A>, A>
pub fn group(self) -> Doc<'a, BoxDoc<'a, A>, A>
Mark this document as a group.
Groups are layed out on a single line if possible. Within a group, all basic documents with several possible layouts are assigned the same layout, that is, they are all layed out horizontally and combined into a one single line, or they are each layed out on their own line.
Sourcepub fn nest(self, offset: usize) -> Doc<'a, BoxDoc<'a, A>, A>
pub fn nest(self, offset: usize) -> Doc<'a, BoxDoc<'a, A>, A>
Increase the indentation level of this document.
pub fn annotate(self, ann: A) -> Doc<'a, BoxDoc<'a, A>, A>
Source§impl<'a, T, A> Doc<'a, T, A>
impl<'a, T, A> Doc<'a, T, A>
Sourcepub fn render<'b, W>(&'b self, width: usize, out: &mut W) -> Result<()>
pub fn render<'b, W>(&'b self, width: usize, out: &mut W) -> Result<()>
Writes a rendered document to a std::io::Write
object.
Sourcepub fn render_fmt<'b, W>(&'b self, width: usize, out: &mut W) -> Result
pub fn render_fmt<'b, W>(&'b self, width: usize, out: &mut W) -> Result
Writes a rendered document to a std::fmt::Write
object.
Sourcepub fn render_raw<'b, W>(
&'b self,
width: usize,
out: &mut W,
) -> Result<(), W::Error>
pub fn render_raw<'b, W>( &'b self, width: usize, out: &mut W, ) -> Result<(), W::Error>
Writes a rendered document to a RenderAnnotated<A>
object.