Struct pretty::DocBuilder[][src]

pub struct DocBuilder<'a, D, A = ()>(pub &'a D, pub BuildDoc<'a, D::Doc, A>)
where
    D: ?Sized + DocAllocator<'a, A>
;
Expand description

The DocBuilder type allows for convenient appending of documents even for arena allocated documents by storing the arena inline.

Tuple Fields

0: &'a D1: BuildDoc<'a, D::Doc, A>

Implementations

Append the given document after this document.

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

use pretty::{Arena, DocAllocator};

let arena = Arena::<()>::new();
let body = arena.line().append("x");
let doc = arena.text("let")
    .append(arena.line())
    .append("x")
    .group()
    .append(
        body.clone()
            .flat_alt(
                arena.line()
                    .append("in")
                    .append(body)
            )
    )
    .group();

assert_eq!(doc.1.pretty(100).to_string(), "let x in x");
assert_eq!(doc.1.pretty(8).to_string(), "let x\nx");

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.

Increase the indentation level of this document.

Lays out self so with the nesting level set to the current column

NOTE: The doc pointer type, D may need to be cloned. Consider using cheaply cloneable ptr like RefDoc or RcDoc

use pretty::DocAllocator;

let arena = pretty::Arena::<()>::new();
let doc = arena.text("lorem").append(arena.text(" "))
    .append(arena.intersperse(["ipsum", "dolor"].iter().cloned(), arena.line_()).align());
assert_eq!(doc.1.pretty(80).to_string(), "lorem ipsum\n      dolor");

Lays out self with a nesting level set to the current level plus adjust.

NOTE: The doc pointer type, D may need to be cloned. Consider using cheaply cloneable ptr like RefDoc or RcDoc

use pretty::DocAllocator;

let arena = pretty::Arena::<()>::new();
let doc = arena.text("prefix").append(arena.text(" "))
    .append(arena.reflow("Indenting these words with nest").hang(4));
assert_eq!(
    doc.1.pretty(24).to_string(),
    "prefix Indenting these\n           words with\n           nest",
);

Indents self by adjust spaces from the current cursor position

NOTE: The doc pointer type, D may need to be cloned. Consider using cheaply cloneable ptr like RefDoc or RcDoc

use pretty::DocAllocator;

let arena = pretty::Arena::<()>::new();
let doc = arena.text("prefix").append(arena.text(" "))
    .append(arena.reflow("The indent function indents these words!").indent(4));
assert_eq!(
    doc.1.pretty(24).to_string(),
"
prefix     The indent
           function
           indents these
           words!".trim_start(),
);

Lays out self and provides the column width of it available to f

NOTE: The doc pointer type, D may need to be cloned. Consider using cheaply cloneable ptr like RefDoc or RcDoc

use pretty::DocAllocator;

let arena = pretty::Arena::<()>::new();
let doc = arena.text("prefix ")
    .append(arena.column(|l| {
        arena.text("| <- column ").append(arena.as_string(l)).into_doc()
    }));
assert_eq!(doc.1.pretty(80).to_string(), "prefix | <- column 7");

Puts self between before and after

Methods from Deref<Target = Doc<'a, D::Doc, A>>

Writes a rendered document to a std::io::Write object.

Writes a rendered document to a std::fmt::Write object.

Writes a rendered document to a RenderAnnotated<A> object.

Returns a value which implements std::fmt::Display

use pretty::{Doc, BoxDoc};
let doc = BoxDoc::<()>::group(
    BoxDoc::text("hello").append(Doc::line()).append(Doc::text("world"))
);
assert_eq!(format!("{}", doc.pretty(80)), "hello world");

Trait Implementations

The resulting type after applying the + operator.

Performs the + operation. Read more

Performs the += operation. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

The resulting type after dereferencing.

Dereferences the value.

Performs the conversion.

Converts self into a document

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.