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.
Trait Implementations§
source§impl<'a, D, A> Into<Doc<'a, <D as DocAllocator<'a, A>>::Doc, A>> for DocBuilder<'a, D, A>where
D: ?Sized + DocAllocator<'a, A>,
impl<'a, D, A> Into<Doc<'a, <D as DocAllocator<'a, A>>::Doc, A>> for DocBuilder<'a, D, A>where
D: ?Sized + DocAllocator<'a, A>,
source§impl<'a, T: Ord, A: Ord> Ord for Doc<'a, T, A>
impl<'a, T: Ord, A: Ord> Ord for Doc<'a, T, A>
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
source§impl<'a, T: PartialEq, A: PartialEq> PartialEq for Doc<'a, T, A>
impl<'a, T: PartialEq, A: PartialEq> PartialEq for Doc<'a, T, A>
source§impl<'a, T: PartialOrd, A: PartialOrd> PartialOrd for Doc<'a, T, A>
impl<'a, T: PartialOrd, A: PartialOrd> PartialOrd for Doc<'a, T, A>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more