[][src]Struct render_tree::document::Document

pub struct Document { /* fields omitted */ }

The Document is the root node in a render tree.

The tree! macro produces a Document, and you can also build one manually.

use render_tree::prelude::*;
use render_tree::Render;

fn main() -> std::io::Result<()> {
    let document = Document::empty()
        // You can add a `Line` to a document, with nested content
        .add(Line(
            // Strings implement `Render`
            "Hello"
        ))
        .add(Line(
            1.add(".").add(10)
        ))
        .add(Section("code", |doc|
            doc.add("[E").add(1000).add("]")
        ));

    assert_eq!(document.to_string()?, "Hello\n1.10\n[E1000]");

    Ok(())
}

The above example is equivalent to this use of the tree! macro:

#[macro_use]
extern crate render_tree;
use render_tree::prelude::*;

fn main() -> std::io::Result<()> {
    let document = tree! {
        <Line as { "Hello" }>
        <Line as {
            {1} "." {10}
        }>
        <Section name="code" as {
            "[E" {1000} "]"
        }>
    };

    assert_eq!(document.to_string()?, "Hello\n1.10\n[E1000]");

    Ok(())
}

Methods

impl Document
[src]

pub fn debug_write(
    &self,
    writer: &mut impl WriteColor,
    stylesheet: &Stylesheet
) -> Result<()>
[src]

impl Document
[src]

pub fn empty() -> Document
[src]

pub fn with(
    renderable: impl Render
) -> Document
[src]

pub fn add(
    self,
    renderable: impl Render
) -> Document
[src]

pub fn write(self) -> Result<()>
[src]

pub fn to_string(self) -> Result<String>
[src]

pub fn write_styled(self, stylesheet: &Stylesheet) -> Result<()>
[src]

pub fn write_with(
    self,
    writer: &mut impl WriteColor,
    stylesheet: &Stylesheet
) -> Result<()>
[src]

Trait Implementations

impl Render for Document
[src]

A Document is rendered by extending its nodes onto the original document.

fn into_fragment(self) -> Document
[src]

fn add<Right: Render>(self, other: Right) -> Combine<Self, Right>
[src]

impl Clone for Document
[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl Debug for Document
[src]

Auto Trait Implementations

impl Send for Document

impl Sync for Document

Blanket Implementations

impl<T> From for T
[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

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

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Any for T where
    T: 'static + ?Sized
[src]