pretty

Enum Doc

Source
pub enum Doc<'a, T, A = ()>
where T: DocPtr<'a, A>,
{
Show 15 variants Nil, Append(T, T), Group(T), FlatAlt(T, T), Nest(isize, T), Hardline, RenderLen(usize, T), OwnedText(Box<str>), BorrowedText(&'a str), SmallText(SmallText), Annotated(A, T), Union(T, T), Column(T::ColumnFn), Nesting(T::ColumnFn), Fail,
}
Expand description

The concrete document type. This type is not meant to be used directly. Instead use the static functions on Doc or the methods on an DocAllocator.

The T parameter is used to abstract over pointers to Doc. See RefDoc and BoxDoc for how it is used

Variants§

§

Nil

§

Append(T, T)

§

Group(T)

§

FlatAlt(T, T)

§

Nest(isize, T)

§

Hardline

§

RenderLen(usize, T)

§

OwnedText(Box<str>)

§

BorrowedText(&'a str)

§

SmallText(SmallText)

§

Annotated(A, T)

§

Union(T, T)

§

Column(T::ColumnFn)

§

Nesting(T::ColumnFn)

§

Fail

Implementations§

Source§

impl<'a, D, A> Doc<'a, D, A>
where D: DocPtr<'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, D, A> Doc<'a, D, A>
where D: StaticDoc<'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, T, A> Doc<'a, T, A>
where T: StaticDoc<'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§

impl<'a, T, A> Doc<'a, T, A>
where T: DocPtr<'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) -> Result
where 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");

Trait Implementations§

Source§

impl<'a, T, A: Clone> Clone for Doc<'a, T, A>
where T: DocPtr<'a, A> + Clone, T::ColumnFn: Clone,

Source§

fn clone(&self) -> Doc<'a, T, 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, T, A> Debug for Doc<'a, T, A>
where T: DocPtr<'a, A> + Debug, A: Debug,

Source§

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

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

impl<'a, T, A> Default for Doc<'a, T, A>
where T: DocPtr<'a, A>,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

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

Source§

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

Converts to this type from the input type.
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, T, A> From<Doc<'a, T, A>> for BuildDoc<'a, T, A>
where T: DocPtr<'a, A>,

Source§

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

Converts to this type from the input type.
Source§

impl<'a, T, A, S> From<S> for Doc<'a, T, A>
where T: StaticDoc<'a, A>, S: Into<Cow<'a, str>>,

Source§

fn from(s: S) -> Doc<'a, T, A>

Converts to this type from the input type.
Source§

impl<'a, D, A> Pretty<'a, D, A> for Doc<'a, D::Doc, A>
where A: 'a, D: ?Sized + DocAllocator<'a, A>,

Source§

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

Converts self into a document

Auto Trait Implementations§

§

impl<'a, T, A> Freeze for Doc<'a, T, A>
where T: Freeze, A: Freeze, <T as DocPtr<'a, A>>::ColumnFn: Freeze,

§

impl<'a, T, A> RefUnwindSafe for Doc<'a, T, A>

§

impl<'a, T, A> Send for Doc<'a, T, A>
where T: Send, A: Send, <T as DocPtr<'a, A>>::ColumnFn: Send,

§

impl<'a, T, A> Sync for Doc<'a, T, A>
where T: Sync, A: Sync, <T as DocPtr<'a, A>>::ColumnFn: Sync,

§

impl<'a, T, A> Unpin for Doc<'a, T, A>
where T: Unpin, A: Unpin, <T as DocPtr<'a, A>>::ColumnFn: Unpin,

§

impl<'a, T, A> UnwindSafe for Doc<'a, T, A>
where T: UnwindSafe, A: UnwindSafe, <T as DocPtr<'a, A>>::ColumnFn: UnwindSafe,

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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 T
where 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 T
where T: Clone,

Source§

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 T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.