pub struct BoxDoc<'a, A = ()>(/* private fields */);
Implementations§
source§impl<'a, A> BoxDoc<'a, A>
impl<'a, A> BoxDoc<'a, A>
sourcepub fn as_string<U: Display>(data: U) -> Self
pub fn as_string<U: Display>(data: U) -> Self
The text t.to_string()
.
The given text must not contain line breaks.
sourcepub fn text<U: Into<Cow<'a, str>>>(data: U) -> Self
pub fn text<U: Into<Cow<'a, str>>>(data: U) -> Self
The given text, which must not contain line breaks.
sourcepub fn append<D>(self, that: D) -> Selfwhere
D: Pretty<'a, BoxAllocator, A>,
pub fn append<D>(self, that: D) -> Selfwhere
D: Pretty<'a, BoxAllocator, A>,
Append the given document after this document.
sourcepub fn intersperse<I, S>(docs: I, separator: S) -> Selfwhere
I: IntoIterator,
I::Item: Pretty<'a, BoxAllocator, A>,
S: Pretty<'a, BoxAllocator, A> + Clone,
A: Clone,
pub fn intersperse<I, S>(docs: I, separator: S) -> Selfwhere
I: IntoIterator,
I::Item: Pretty<'a, BoxAllocator, A>,
S: Pretty<'a, BoxAllocator, 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]
.
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
sourcepub fn flat_alt<D>(self, doc: D) -> Selfwhere
D: Pretty<'a, BoxAllocator, A>,
pub fn flat_alt<D>(self, doc: D) -> Selfwhere
D: Pretty<'a, BoxAllocator, A>,
Acts as self
when laid out on multiple lines and acts as that
when laid out on a single line.
sourcepub fn group(self) -> Self
pub fn group(self) -> Self
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 annotate(self, ann: A) -> Self
pub fn union<D>(self, other: D) -> Self
pub fn softline() -> Self
sourcepub fn softline_() -> Self
pub fn softline_() -> Self
A softline_
acts like nil
if the document fits the page, otherwise like line_
pub fn column(f: impl Fn(usize) -> Self + 'static) -> Self
pub fn nesting(f: impl Fn(usize) -> Self + 'static) -> Self
Methods from Deref<Target = Doc<'a, BoxDoc<'a, A>, A>>§
sourcepub fn render<W>(&self, width: usize, out: &mut W) -> Result<()>
pub fn render<W>(&self, width: usize, out: &mut W) -> Result<()>
Writes a rendered document to a std::io::Write
object.
sourcepub fn render_fmt<W>(&self, width: usize, out: &mut W) -> Result
pub fn render_fmt<W>(&self, width: usize, out: &mut W) -> Result
Writes a rendered document to a std::fmt::Write
object.
sourcepub fn render_raw<W>(&self, width: usize, out: &mut W) -> Result<(), W::Error>where
for<'b> W: RenderAnnotated<'b, A> + ?Sized,
pub fn render_raw<W>(&self, width: usize, out: &mut W) -> Result<(), W::Error>where
for<'b> W: RenderAnnotated<'b, A> + ?Sized,
Writes a rendered document to a RenderAnnotated<A>
object.
sourcepub fn pretty<'d>(&'d self, width: usize) -> PrettyFmt<'a, 'd, T, A>
pub fn pretty<'d>(&'d self, width: usize) -> PrettyFmt<'a, 'd, T, A>
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§
source§impl<'a, A> Pretty<'a, BoxAllocator, A> for BoxDoc<'a, A>where
A: 'a,
impl<'a, A> Pretty<'a, BoxAllocator, A> for BoxDoc<'a, A>where
A: 'a,
source§fn pretty(self, allocator: &'a BoxAllocator) -> DocBuilder<'a, BoxAllocator, A>
fn pretty(self, allocator: &'a BoxAllocator) -> DocBuilder<'a, BoxAllocator, A>
self
into a documentAuto Trait Implementations§
impl<'a, A> Freeze for BoxDoc<'a, A>
impl<'a, A = ()> !RefUnwindSafe for BoxDoc<'a, A>
impl<'a, A = ()> !Send for BoxDoc<'a, A>
impl<'a, A = ()> !Sync for BoxDoc<'a, A>
impl<'a, A> Unpin for BoxDoc<'a, A>
impl<'a, A = ()> !UnwindSafe for BoxDoc<'a, A>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)