Struct pretty::RcDoc

source ·
pub struct RcDoc<'a, A = ()>(/* private fields */);

Implementations§

source§

impl<'a, A> RcDoc<'a, A>

source

pub fn new(doc: Doc<'a, RcDoc<'a, A>, A>) -> RcDoc<'a, A>

source§

impl<'a, A> RcDoc<'a, A>

source

pub fn nil() -> Self

An empty document.

source

pub fn hardline() -> Self

A single hardline.

source

pub fn space() -> Self

source

pub fn fail() -> Self

source§

impl<'a, A> RcDoc<'a, A>

source

pub fn line() -> Self

A line acts like a \n but behaves like space if it is grouped on a single line.

source

pub fn line_() -> Self

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

source§

impl<'a, A> RcDoc<'a, A>

source

pub fn as_string<U: Display>(data: U) -> Self

The text t.to_string().

The given text must not contain line breaks.

source

pub fn text<U: Into<Cow<'a, str>>>(data: U) -> Self

The given text, which must not contain line breaks.

source

pub fn append<D>(self, that: D) -> Selfwhere D: Pretty<'a, RcAllocator, A>,

Append the given document after this document.

source

pub fn concat<I>(docs: I) -> Selfwhere I: IntoIterator, I::Item: Pretty<'a, RcAllocator, A>,

A single document concatenating all the given documents.

source

pub fn intersperse<I, S>(docs: I, separator: S) -> Selfwhere I: IntoIterator, I::Item: Pretty<'a, RcAllocator, A>, S: Pretty<'a, RcAllocator, 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

source

pub fn flat_alt<D>(self, doc: D) -> Selfwhere D: Pretty<'a, RcAllocator, A>,

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

source

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.

source

pub fn nest(self, offset: isize) -> Self

Increase the indentation level of this document.

source

pub fn annotate(self, ann: A) -> Self

source

pub fn union<D>(self, other: D) -> Selfwhere D: Into<BuildDoc<'a, Self, A>>,

source

pub fn softline() -> Self

source

pub fn softline_() -> Self

A softline_ acts like nil if the document fits the page, otherwise like line_

source

pub fn column(f: impl Fn(usize) -> Self + 'static) -> Self

source

pub fn nesting(f: impl Fn(usize) -> Self + 'static) -> Self

Methods from Deref<Target = Doc<'a, RcDoc<'a, A>, A>>§

source

pub fn render<W>(&self, width: usize, out: &mut W) -> Result<()>where W: ?Sized + Write,

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

source

pub fn render_fmt<W>(&self, width: usize, out: &mut W) -> Resultwhere W: ?Sized + Write,

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

source

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.

source

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");
source

pub fn render_colored<W>(&self, width: usize, out: W) -> Result<()>where W: WriteColor,

Trait Implementations§

source§

impl<'a, A: Clone> Clone for RcDoc<'a, A>

source§

fn clone(&self) -> RcDoc<'a, A>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'a, A> Debug for RcDoc<'a, A>where A: Debug,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'a, A> Deref for RcDoc<'a, A>

§

type Target = Doc<'a, RcDoc<'a, A>, A>

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl<'a, A> DocPtr<'a, A> for RcDoc<'a, A>

§

type ColumnFn = Rc<dyn Fn(usize) -> RcDoc<'a, A> + 'a, Global>

§

type WidthFn = Rc<dyn Fn(isize) -> RcDoc<'a, A> + 'a, Global>

source§

impl<'a, A> From<Doc<'a, RcDoc<'a, A>, A>> for RcDoc<'a, A>

source§

fn from(doc: Doc<'a, RcDoc<'a, A>, A>) -> RcDoc<'a, A>

Converts to this type from the input type.
source§

impl<'a, A> From<RcDoc<'a, A>> for BuildDoc<'a, RcDoc<'a, A>, A>

source§

fn from(s: RcDoc<'a, A>) -> Self

Converts to this type from the input type.
source§

impl<'a, A> Pretty<'a, RcAllocator, A> for RcDoc<'a, A>where A: 'a,

source§

fn pretty(self, allocator: &'a RcAllocator) -> DocBuilder<'a, RcAllocator, A>

Converts self into a document
source§

impl<'a, A> StaticDoc<'a, A> for RcDoc<'a, A>

§

type Allocator = RcAllocator

source§

const ALLOCATOR: &'static Self::Allocator = _

Auto Trait Implementations§

§

impl<'a, A = ()> !RefUnwindSafe for RcDoc<'a, A>

§

impl<'a, A = ()> !Send for RcDoc<'a, A>

§

impl<'a, A = ()> !Sync for RcDoc<'a, A>

§

impl<'a, A> Unpin for RcDoc<'a, A>

§

impl<'a, A = ()> !UnwindSafe for RcDoc<'a, A>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.