[−][src]Trait pretty::DocAllocator
The DocAllocator
trait abstracts over a type which can allocate (pointers to) Doc
.
Associated Types
Loading content...Required methods
fn alloc(&'a self, doc: Doc<'a, Self::Doc, A>) -> Self::Doc
fn alloc_column_fn(
&'a self,
f: impl Fn(usize) -> Self::Doc + 'a
) -> <Self::Doc as DocPtr<'a, A>>::ColumnFn
&'a self,
f: impl Fn(usize) -> Self::Doc + 'a
) -> <Self::Doc as DocPtr<'a, A>>::ColumnFn
fn alloc_width_fn(
&'a self,
f: impl Fn(isize) -> Self::Doc + 'a
) -> <Self::Doc as DocPtr<'a, A>>::WidthFn
&'a self,
f: impl Fn(isize) -> Self::Doc + 'a
) -> <Self::Doc as DocPtr<'a, A>>::WidthFn
Provided methods
fn alloc_cow(&'a self, doc: BuildDoc<'a, Self::Doc, A>) -> Self::Doc
fn nil(&'a self) -> DocBuilder<'a, Self, A>
Allocate an empty document.
fn fail(&'a self) -> DocBuilder<'a, Self, A>
Fails document rendering immediately.
Primarily used to abort rendering inside the left side of Union
fn hardline(&'a self) -> DocBuilder<'a, Self, A>
Allocate a single hardline.
fn space(&'a self) -> DocBuilder<'a, Self, A>
fn line(&'a self) -> DocBuilder<'a, Self, A>
A line acts like a \n
but behaves like space
if it is grouped on a single line.
fn line_(&'a self) -> DocBuilder<'a, Self, A>
Acts like line
but behaves like nil
if grouped on a single line
use pretty::{Doc, RcDoc}; let doc = RcDoc::<()>::group( RcDoc::text("(") .append( RcDoc::line_() .append(Doc::text("test")) .append(Doc::line()) .append(Doc::text("test")) .nest(2), ) .append(Doc::line_()) .append(Doc::text(")")), ); assert_eq!(doc.pretty(5).to_string(), "(\n test\n test\n)"); assert_eq!(doc.pretty(100).to_string(), "(test test)");
fn softline(&'a self) -> DocBuilder<'a, Self, A>
A softline
acts like space
if the document fits the page, otherwise like line
fn softline_(&'a self) -> DocBuilder<'a, Self, A>
A softline_
acts like nil
if the document fits the page, otherwise like line_
fn as_string<U: Display>(&'a self, data: U) -> DocBuilder<'a, Self, A>
Allocate a document containing the text t.to_string()
.
The given text must not contain line breaks.
fn text<U: Into<Cow<'a, str>>>(&'a self, data: U) -> DocBuilder<'a, Self, A>
Allocate a document containing the given text.
The given text must not contain line breaks.
fn concat<I>(&'a self, docs: I) -> DocBuilder<'a, Self, A> where
I: IntoIterator,
I::Item: Into<BuildDoc<'a, Self::Doc, A>>,
I: IntoIterator,
I::Item: Into<BuildDoc<'a, Self::Doc, A>>,
Allocate a document concatenating the given documents.
fn intersperse<I, S>(&'a self, docs: I, separator: S) -> DocBuilder<'a, Self, A> where
I: IntoIterator,
I::Item: Into<BuildDoc<'a, Self::Doc, A>>,
S: Into<BuildDoc<'a, Self::Doc, A>> + Clone,
I: IntoIterator,
I::Item: Into<BuildDoc<'a, Self::Doc, A>>,
S: Into<BuildDoc<'a, Self::Doc, A>> + Clone,
Allocate a document that intersperses the given separator S
between the given documents
[A, B, C, ..., Z]
, yielding [A, S, B, S, C, S, ..., S, Z]
.
Compare the intersperse
method from the itertools
crate.
NOTE: The separator type, S
may need to be cloned. Consider using cheaply cloneable ptr
like RefDoc
or RcDoc
fn column(
&'a self,
f: impl Fn(usize) -> Self::Doc + 'a
) -> DocBuilder<'a, Self, A>
&'a self,
f: impl Fn(usize) -> Self::Doc + 'a
) -> DocBuilder<'a, Self, A>
Allocate a document that acts differently based on the position and page layout
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");
fn nesting(
&'a self,
f: impl Fn(usize) -> Self::Doc + 'a
) -> DocBuilder<'a, Self, A>
&'a self,
f: impl Fn(usize) -> Self::Doc + 'a
) -> DocBuilder<'a, Self, A>
Allocate a document that acts differently based on the current nesting level
use pretty::DocAllocator; let arena = pretty::Arena::<()>::new(); let doc = arena.text("prefix ") .append(arena.nesting(|l| { arena.text("[Nested: ").append(arena.as_string(l)).append("]").into_doc() }).nest(4)); assert_eq!(doc.1.pretty(80).to_string(), "prefix [Nested: 4]");
fn reflow(&'a self, text: &'a str) -> DocBuilder<'a, Self, A> where
Self: Sized,
Self::Doc: Clone,
A: Clone,
Self: Sized,
Self::Doc: Clone,
A: Clone,
Reflows text
inserting softline
in place of any whitespace
Implementations on Foreign Types
impl<'a, D: ?Sized, A> DocAllocator<'a, A> for &'a D where
D: DocAllocator<'a, A>,
A: 'a,
[src]
D: DocAllocator<'a, A>,
A: 'a,
type Doc = D::Doc
fn alloc(&'a self, doc: Doc<'a, Self::Doc, A>) -> Self::Doc
[src]
fn alloc_column_fn(
&'a self,
f: impl Fn(usize) -> Self::Doc + 'a
) -> <Self::Doc as DocPtr<'a, A>>::ColumnFn
[src]
&'a self,
f: impl Fn(usize) -> Self::Doc + 'a
) -> <Self::Doc as DocPtr<'a, A>>::ColumnFn
fn alloc_width_fn(
&'a self,
f: impl Fn(isize) -> Self::Doc + 'a
) -> <Self::Doc as DocPtr<'a, A>>::WidthFn
[src]
&'a self,
f: impl Fn(isize) -> Self::Doc + 'a
) -> <Self::Doc as DocPtr<'a, A>>::WidthFn
Implementors
impl<'a, A> DocAllocator<'a, A> for Arena<'a, A>
[src]
type Doc = RefDoc<'a, A>
fn alloc(&'a self, doc: Doc<'a, Self::Doc, A>) -> Self::Doc
[src]
fn alloc_column_fn(
&'a self,
f: impl Fn(usize) -> Self::Doc + 'a
) -> <Self::Doc as DocPtr<'a, A>>::ColumnFn
[src]
&'a self,
f: impl Fn(usize) -> Self::Doc + 'a
) -> <Self::Doc as DocPtr<'a, A>>::ColumnFn
fn alloc_width_fn(
&'a self,
f: impl Fn(isize) -> Self::Doc + 'a
) -> <Self::Doc as DocPtr<'a, A>>::WidthFn
[src]
&'a self,
f: impl Fn(isize) -> Self::Doc + 'a
) -> <Self::Doc as DocPtr<'a, A>>::WidthFn
impl<'a, A> DocAllocator<'a, A> for BoxAllocator where
A: 'a,
[src]
A: 'a,
type Doc = BoxDoc<'a, A>
fn alloc(&'a self, doc: Doc<'a, Self::Doc, A>) -> Self::Doc
[src]
fn alloc_column_fn(
&'a self,
f: impl Fn(usize) -> Self::Doc + 'a
) -> <Self::Doc as DocPtr<'a, A>>::ColumnFn
[src]
&'a self,
f: impl Fn(usize) -> Self::Doc + 'a
) -> <Self::Doc as DocPtr<'a, A>>::ColumnFn
fn alloc_width_fn(
&'a self,
f: impl Fn(isize) -> Self::Doc + 'a
) -> <Self::Doc as DocPtr<'a, A>>::WidthFn
[src]
&'a self,
f: impl Fn(isize) -> Self::Doc + 'a
) -> <Self::Doc as DocPtr<'a, A>>::WidthFn
impl<'a, A> DocAllocator<'a, A> for RcAllocator where
A: 'a,
[src]
A: 'a,
type Doc = RcDoc<'a, A>
fn alloc(&'a self, doc: Doc<'a, Self::Doc, A>) -> Self::Doc
[src]
fn alloc_column_fn(
&'a self,
f: impl Fn(usize) -> Self::Doc + 'a
) -> <Self::Doc as DocPtr<'a, A>>::ColumnFn
[src]
&'a self,
f: impl Fn(usize) -> Self::Doc + 'a
) -> <Self::Doc as DocPtr<'a, A>>::ColumnFn
fn alloc_width_fn(
&'a self,
f: impl Fn(isize) -> Self::Doc + 'a
) -> <Self::Doc as DocPtr<'a, A>>::WidthFn
[src]
&'a self,
f: impl Fn(isize) -> Self::Doc + 'a
) -> <Self::Doc as DocPtr<'a, A>>::WidthFn