[−][src]Struct pretty::DocBuilder
The DocBuilder
type allows for convenient appending of documents even for arena allocated
documents by storing the arena inline.
Methods
impl<'a, 's, D: ?Sized, A> DocBuilder<'a, D, A> where
D: DocAllocator<'a, A>,
[src]
D: DocAllocator<'a, A>,
pub fn append<E>(self, that: E) -> DocBuilder<'a, D, A> where
E: Into<BuildDoc<'a, D::Doc, A>>,
[src]
E: Into<BuildDoc<'a, D::Doc, A>>,
Append the given document after this document.
pub fn flat_alt<E>(self, that: E) -> DocBuilder<'a, D, A> where
E: Into<BuildDoc<'a, D::Doc, A>>,
[src]
E: Into<BuildDoc<'a, D::Doc, A>>,
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");
pub fn group(self) -> DocBuilder<'a, D, 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: isize) -> DocBuilder<'a, D, A>
[src]
Increase the indentation level of this document.
pub fn annotate(self, ann: A) -> DocBuilder<'a, D, A>
[src]
pub fn union<E>(self, other: E) -> DocBuilder<'a, D, A> where
E: Into<BuildDoc<'a, D::Doc, A>>,
[src]
E: Into<BuildDoc<'a, D::Doc, A>>,
pub fn align(self) -> DocBuilder<'a, D, A> where
DocBuilder<'a, D, A>: Clone,
[src]
DocBuilder<'a, D, A>: Clone,
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");
pub fn hang(self, adjust: isize) -> DocBuilder<'a, D, A> where
DocBuilder<'a, D, A>: Clone,
[src]
DocBuilder<'a, D, A>: Clone,
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", );
pub fn indent(self, adjust: usize) -> DocBuilder<'a, D, A> where
DocBuilder<'a, D, A>: Clone,
[src]
DocBuilder<'a, D, A>: Clone,
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(), );
pub fn width(self, f: impl Fn(isize) -> D::Doc + 'a) -> DocBuilder<'a, D, A> where
BuildDoc<'a, D::Doc, A>: Clone,
[src]
BuildDoc<'a, D::Doc, A>: Clone,
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");
pub fn enclose<E, F>(self, before: E, after: F) -> DocBuilder<'a, D, A> where
E: Into<BuildDoc<'a, D::Doc, A>>,
F: Into<BuildDoc<'a, D::Doc, A>>,
[src]
E: Into<BuildDoc<'a, D::Doc, A>>,
F: Into<BuildDoc<'a, D::Doc, A>>,
Puts self
between before
and after
pub fn single_quotes(self) -> DocBuilder<'a, D, A>
[src]
pub fn double_quotes(self) -> DocBuilder<'a, D, A>
[src]
pub fn parens(self) -> DocBuilder<'a, D, A>
[src]
pub fn angles(self) -> DocBuilder<'a, D, A>
[src]
pub fn braces(self) -> DocBuilder<'a, D, A>
[src]
pub fn brackets(self) -> DocBuilder<'a, D, A>
[src]
pub fn into_doc(self) -> D::Doc
[src]
Trait Implementations
impl<'a, A, D> Clone for DocBuilder<'a, D, A> where
A: Clone,
D: DocAllocator<'a, A> + 'a,
D::Doc: Clone,
[src]
A: Clone,
D: DocAllocator<'a, A> + 'a,
D::Doc: Clone,
fn clone(&self) -> Self
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<'a, D: ?Sized, A> Into<BuildDoc<'a, <D as DocAllocator<'a, A>>::Doc, A>> for DocBuilder<'a, D, A> where
D: DocAllocator<'a, A>,
[src]
D: DocAllocator<'a, A>,
Auto Trait Implementations
impl<'a, D: ?Sized, A> RefUnwindSafe for DocBuilder<'a, D, A> where
A: RefUnwindSafe,
D: RefUnwindSafe,
<<D as DocAllocator<'a, A>>::Doc as DocPtr<'a, A>>::ColumnFn: RefUnwindSafe,
<D as DocAllocator<'a, A>>::Doc: DocPtr<'a, A> + RefUnwindSafe,
A: RefUnwindSafe,
D: RefUnwindSafe,
<<D as DocAllocator<'a, A>>::Doc as DocPtr<'a, A>>::ColumnFn: RefUnwindSafe,
<D as DocAllocator<'a, A>>::Doc: DocPtr<'a, A> + RefUnwindSafe,
impl<'a, D: ?Sized, A> Send for DocBuilder<'a, D, A> where
A: Send,
D: Sync,
<<D as DocAllocator<'a, A>>::Doc as DocPtr<'a, A>>::ColumnFn: Send,
<D as DocAllocator<'a, A>>::Doc: DocPtr<'a, A> + Send,
A: Send,
D: Sync,
<<D as DocAllocator<'a, A>>::Doc as DocPtr<'a, A>>::ColumnFn: Send,
<D as DocAllocator<'a, A>>::Doc: DocPtr<'a, A> + Send,
impl<'a, D: ?Sized, A> Sync for DocBuilder<'a, D, A> where
A: Sync,
D: Sync,
<<D as DocAllocator<'a, A>>::Doc as DocPtr<'a, A>>::ColumnFn: Sync,
<D as DocAllocator<'a, A>>::Doc: DocPtr<'a, A> + Sync,
A: Sync,
D: Sync,
<<D as DocAllocator<'a, A>>::Doc as DocPtr<'a, A>>::ColumnFn: Sync,
<D as DocAllocator<'a, A>>::Doc: DocPtr<'a, A> + Sync,
impl<'a, D: ?Sized, A> Unpin for DocBuilder<'a, D, A> where
A: Unpin,
<<D as DocAllocator<'a, A>>::Doc as DocPtr<'a, A>>::ColumnFn: Unpin,
<D as DocAllocator<'a, A>>::Doc: DocPtr<'a, A> + Unpin,
A: Unpin,
<<D as DocAllocator<'a, A>>::Doc as DocPtr<'a, A>>::ColumnFn: Unpin,
<D as DocAllocator<'a, A>>::Doc: DocPtr<'a, A> + Unpin,
impl<'a, D: ?Sized, A> UnwindSafe for DocBuilder<'a, D, A> where
A: UnwindSafe,
D: RefUnwindSafe,
<<D as DocAllocator<'a, A>>::Doc as DocPtr<'a, A>>::ColumnFn: UnwindSafe,
<D as DocAllocator<'a, A>>::Doc: DocPtr<'a, A> + UnwindSafe,
A: UnwindSafe,
D: RefUnwindSafe,
<<D as DocAllocator<'a, A>>::Doc as DocPtr<'a, A>>::ColumnFn: UnwindSafe,
<D as DocAllocator<'a, A>>::Doc: DocPtr<'a, A> + UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,