Enum pretty::Doc [−][src]
pub enum Doc<'a, T, A = ()> { Nil, Append(T, T), Group(T), Nest(usize, T), Space, Newline, Text(Cow<'a, str>), Annotated(A, T), }
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
Nil
Append(T, T)
Group(T)
Nest(usize, T)
Space
Newline
Text(Cow<'a, str>)
Annotated(A, T)
Methods
impl<'a, T, A> Doc<'a, T, A>
[src]
impl<'a, T, A> Doc<'a, T, A>
pub fn nil() -> Doc<'a, T, A>
[src]
pub fn nil() -> Doc<'a, T, A>
An empty document.
pub fn as_string<U: ToString>(data: U) -> Doc<'a, T, A>
[src]
pub fn as_string<U: ToString>(data: U) -> Doc<'a, T, A>
The text t.to_string()
.
The given text must not contain line breaks.
pub fn newline() -> Doc<'a, T, A>
[src]
pub fn newline() -> Doc<'a, T, A>
A single newline.
pub fn text<U: Into<Cow<'a, str>>>(data: U) -> Doc<'a, T, A>
[src]
pub fn text<U: Into<Cow<'a, str>>>(data: U) -> Doc<'a, T, A>
The given text, which must not contain line breaks.
pub fn space() -> Doc<'a, T, A>
[src]
pub fn space() -> Doc<'a, T, A>
A space.
impl<'a, A> Doc<'a, BoxDoc<'a, A>, A>
[src]
impl<'a, A> Doc<'a, BoxDoc<'a, A>, A>
pub fn append<D>(self, that: D) -> Doc<'a, BoxDoc<'a, A>, A> where
D: Into<Doc<'a, BoxDoc<'a, A>, A>>,
[src]
pub fn append<D>(self, that: D) -> Doc<'a, BoxDoc<'a, A>, A> where
D: Into<Doc<'a, BoxDoc<'a, A>, A>>,
Append the given document after this document.
pub fn concat<I>(docs: I) -> Doc<'a, BoxDoc<'a, A>, A> where
I: IntoIterator,
I::Item: Into<Doc<'a, BoxDoc<'a, A>, A>>,
[src]
pub fn concat<I>(docs: I) -> Doc<'a, BoxDoc<'a, A>, A> where
I: IntoIterator,
I::Item: Into<Doc<'a, BoxDoc<'a, A>, A>>,
A single document concatenating all the given documents.
pub fn intersperse<I, S>(docs: I, separator: S) -> Doc<'a, BoxDoc<'a, A>, A> where
I: IntoIterator,
I::Item: Into<Doc<'a, BoxDoc<'a, A>, A>>,
S: Into<Doc<'a, BoxDoc<'a, A>, A>> + Clone,
A: Clone,
[src]
pub fn intersperse<I, S>(docs: I, separator: S) -> Doc<'a, BoxDoc<'a, A>, A> where
I: IntoIterator,
I::Item: Into<Doc<'a, BoxDoc<'a, A>, A>>,
S: Into<Doc<'a, BoxDoc<'a, A>, A>> + Clone,
A: Clone,
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]
.
pub fn group(self) -> Doc<'a, BoxDoc<'a, A>, A>
[src]
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.
pub fn nest(self, offset: usize) -> Doc<'a, BoxDoc<'a, A>, A>
[src]
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>
[src]
pub fn annotate(self, ann: A) -> Doc<'a, BoxDoc<'a, A>, A>
impl<'a, T, A> Doc<'a, T, A>
[src]
impl<'a, T, A> Doc<'a, T, A>
pub fn render<'b, W: ?Sized>(&'b self, width: usize, out: &mut W) -> Result<()> where
T: Deref<Target = Doc<'b, T, A>>,
W: Write,
[src]
pub fn render<'b, W: ?Sized>(&'b self, width: usize, out: &mut W) -> Result<()> where
T: Deref<Target = Doc<'b, T, A>>,
W: Write,
Writes a rendered document to a std::io::Write
object.
pub fn render_fmt<'b, W: ?Sized>(&'b self, width: usize, out: &mut W) -> Result where
T: Deref<Target = Doc<'b, T, A>>,
W: Write,
[src]
pub fn render_fmt<'b, W: ?Sized>(&'b self, width: usize, out: &mut W) -> Result where
T: Deref<Target = Doc<'b, T, A>>,
W: Write,
Writes a rendered document to a std::fmt::Write
object.
pub fn render_raw<'b, W: ?Sized>(
&'b self,
width: usize,
out: &mut W
) -> Result<(), W::Error> where
T: Deref<Target = Doc<'b, T, A>>,
W: RenderAnnotated<A>,
[src]
pub fn render_raw<'b, W: ?Sized>(
&'b self,
width: usize,
out: &mut W
) -> Result<(), W::Error> where
T: Deref<Target = Doc<'b, T, A>>,
W: RenderAnnotated<A>,
Writes a rendered document to a RenderAnnotated<A>
object.
pub fn pretty<'b>(&'b self, width: usize) -> Pretty<'b, T, A> where
T: Deref<Target = Doc<'b, T, A>>,
[src]
pub fn pretty<'b>(&'b self, width: usize) -> Pretty<'b, T, A> where
T: Deref<Target = Doc<'b, T, A>>,
Returns a value which implements std::fmt::Display
use pretty::Doc; let doc = Doc::<_>::group( Doc::text("hello").append(Doc::space()).append(Doc::text("world")) ); assert_eq!(format!("{}", doc.pretty(80)), "hello world");
impl<'a, T> Doc<'a, T, ColorSpec>
[src]
impl<'a, T> Doc<'a, T, ColorSpec>
pub fn render_colored<'b, W>(&'b self, width: usize, out: W) -> Result<()> where
T: Deref<Target = Doc<'b, T, ColorSpec>>,
W: WriteColor,
[src]
pub fn render_colored<'b, W>(&'b self, width: usize, out: W) -> Result<()> where
T: Deref<Target = Doc<'b, T, ColorSpec>>,
W: WriteColor,
Trait Implementations
impl<'a, T: Clone, A: Clone> Clone for Doc<'a, T, A>
[src]
impl<'a, T: Clone, A: Clone> Clone for Doc<'a, T, A>
fn clone(&self) -> Doc<'a, T, A>
[src]
fn clone(&self) -> Doc<'a, T, A>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl<'a, T: Debug, A: Debug> Debug for Doc<'a, T, A>
[src]
impl<'a, T: Debug, A: Debug> Debug for Doc<'a, T, A>
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl<'a, T: Eq, A: Eq> Eq for Doc<'a, T, A>
[src]
impl<'a, T: Eq, A: Eq> Eq for Doc<'a, T, A>
impl<'a, T: Ord, A: Ord> Ord for Doc<'a, T, A>
[src]
impl<'a, T: Ord, A: Ord> Ord for Doc<'a, T, A>
fn cmp(&self, other: &Doc<'a, T, A>) -> Ordering
[src]
fn cmp(&self, other: &Doc<'a, T, A>) -> Ordering
This method returns an Ordering
between self
and other
. Read more
fn max(self, other: Self) -> Self
1.21.0[src]
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.21.0[src]
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
impl<'a, T: PartialEq, A: PartialEq> PartialEq for Doc<'a, T, A>
[src]
impl<'a, T: PartialEq, A: PartialEq> PartialEq for Doc<'a, T, A>
fn eq(&self, other: &Doc<'a, T, A>) -> bool
[src]
fn eq(&self, other: &Doc<'a, T, A>) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Doc<'a, T, A>) -> bool
[src]
fn ne(&self, other: &Doc<'a, T, A>) -> bool
This method tests for !=
.
impl<'a, T: PartialOrd, A: PartialOrd> PartialOrd for Doc<'a, T, A>
[src]
impl<'a, T: PartialOrd, A: PartialOrd> PartialOrd for Doc<'a, T, A>
fn partial_cmp(&self, other: &Doc<'a, T, A>) -> Option<Ordering>
[src]
fn partial_cmp(&self, other: &Doc<'a, T, A>) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, other: &Doc<'a, T, A>) -> bool
[src]
fn lt(&self, other: &Doc<'a, T, A>) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, other: &Doc<'a, T, A>) -> bool
[src]
fn le(&self, other: &Doc<'a, T, A>) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, other: &Doc<'a, T, A>) -> bool
[src]
fn gt(&self, other: &Doc<'a, T, A>) -> bool
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, other: &Doc<'a, T, A>) -> bool
[src]
fn ge(&self, other: &Doc<'a, T, A>) -> bool
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl<'a, T, A, S> From<S> for Doc<'a, T, A> where
S: Into<Cow<'a, str>>,
[src]
impl<'a, T, A, S> From<S> for Doc<'a, T, A> where
S: Into<Cow<'a, str>>,
impl<'a, D: ?Sized, A> Into<Doc<'a, D::Doc, A>> for DocBuilder<'a, D, A> where
D: DocAllocator<'a, A>,
[src]
impl<'a, D: ?Sized, A> Into<Doc<'a, D::Doc, A>> for DocBuilder<'a, D, A> where
D: DocAllocator<'a, A>,