[][src]Struct language_reporting::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<impl WriteColor>(
    &self,
    writer: &mut impl WriteColor,
    stylesheet: &Stylesheet
) -> Result<(), Error> where
    impl WriteColor: WriteColor
[src]

impl Document[src]

pub fn empty() -> Document[src]

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

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

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

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

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

pub fn write_with<impl WriteColor>(
    self,
    writer: &mut impl WriteColor,
    stylesheet: &Stylesheet
) -> Result<(), Error> where
    impl WriteColor: WriteColor
[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>(self, other: Right) -> Combine<Self, Right> where
    Right: Render
[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

Blanket Implementations

impl<T> From<T> for T[src]

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

type Owned = T

The resulting type after obtaining ownership.

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

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

The type returned in the event of a conversion error.

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

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

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

impl<T> Render for T where
    T: Display
[src]

fn into_fragment(self) -> Document[src]

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