[][src]Enum pretty::Doc

pub enum Doc<'a, T, A = ()> {
    Nil,
    Append(T, T),
    Group(T),
    FlatAlt(T, T),
    Nest(usize, T),
    Space,
    Newline,
    Text(Cow<'a, str>),
    Annotated(A, T),
    Union(T, 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)
FlatAlt(T, T)
Nest(usize, T)
Space
Newline
Text(Cow<'a, str>)
Annotated(A, T)
Union(T, T)

Methods

impl<'a, T, A> Doc<'a, T, A>[src]

pub fn nil() -> Doc<'a, T, A>[src]

An empty document.

pub fn as_string<U: ToString>(data: U) -> Doc<'a, T, A>[src]

The text t.to_string().

The given text must not contain line breaks.

pub fn newline() -> Doc<'a, T, A>[src]

A single newline.

pub fn text<U: Into<Cow<'a, str>>>(data: U) -> Doc<'a, T, A>[src]

The given text, which must not contain line breaks.

pub fn space() -> Doc<'a, T, A>[src]

A space.

impl<'a, A> 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>>, 
[src]

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]

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]

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].

Compare the intersperse method from the itertools crate.

pub fn flat_alt<D>(self, doc: D) -> Doc<'a, BoxDoc<'a, A>, A> where
    D: Into<Doc<'a, BoxDoc<'a, A>, A>>, 
[src]

Acts as self when laid out on multiple lines and acts as that when laid out on a single line.

pub fn group(self) -> Doc<'a, BoxDoc<'a, A>, A>[src]

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]

Increase the indentation level of this document.

pub fn space_() -> Doc<'a, BoxDoc<'a, A>, A>[src]

Acts like space but behaves like nil if grouped on a single line

pub fn annotate(self, ann: A) -> Doc<'a, BoxDoc<'a, A>, A>[src]

pub fn union<D>(self, other: D) -> Doc<'a, BoxDoc<'a, A>, A> where
    D: Into<Doc<'a, BoxDoc<'a, A>, A>>, 
[src]

impl<'a, T, A> Doc<'a, T, A>[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
[src]

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]

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]

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]

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]

pub fn render_colored<'b, W>(&'b self, width: usize, out: W) -> Result<()> where
    T: Deref<Target = Doc<'b, T, ColorSpec>>,
    W: WriteColor, 
[src]

Trait Implementations

impl<'a, D: ?Sized, A> Into<Doc<'a, <D as DocAllocator<'a, A>>::Doc, A>> for DocBuilder<'a, D, A> where
    D: DocAllocator<'a, A>, 
[src]

impl<'a, T, A, S> From<S> for Doc<'a, T, A> where
    S: Into<Cow<'a, str>>, 
[src]

impl<'a, T: Clone, A: Clone> Clone for Doc<'a, T, A>[src]

impl<'a, T: Eq, A: Eq> Eq for Doc<'a, T, A>[src]

impl<'a, T: Ord, A: Ord> Ord for Doc<'a, T, A>[src]

impl<'a, T: PartialEq, A: PartialEq> PartialEq<Doc<'a, T, A>> for Doc<'a, T, A>[src]

impl<'a, T: PartialOrd, A: PartialOrd> PartialOrd<Doc<'a, T, A>> for Doc<'a, T, A>[src]

impl<'a, T: Debug, A: Debug> Debug for Doc<'a, T, A>[src]

impl<'a, T, A> StructuralPartialEq for Doc<'a, T, A>[src]

impl<'a, T, A> StructuralEq for Doc<'a, T, A>[src]

Auto Trait Implementations

impl<'a, T, A> Send for Doc<'a, T, A> where
    A: Send,
    T: Send

impl<'a, T, A> Sync for Doc<'a, T, A> where
    A: Sync,
    T: Sync

impl<'a, T, A> Unpin for Doc<'a, T, A> where
    A: Unpin,
    T: Unpin

impl<'a, T, A> UnwindSafe for Doc<'a, T, A> where
    A: UnwindSafe,
    T: UnwindSafe

impl<'a, T, A> RefUnwindSafe for Doc<'a, T, A> where
    A: RefUnwindSafe,
    T: RefUnwindSafe

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]