[−][src]Struct language_reporting::Document
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]
&self,
writer: &mut impl WriteColor,
stylesheet: &Stylesheet
) -> Result<(), Error> where
impl WriteColor: WriteColor,
impl Document
[src]
pub fn empty() -> Document
[src]
pub fn with<impl Render>(renderable: impl Render) -> Document where
impl Render: Render,
[src]
impl Render: Render,
pub fn add<impl Render>(self, renderable: impl Render) -> Document where
impl Render: Render,
[src]
impl Render: Render,
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]
self,
writer: &mut impl WriteColor,
stylesheet: &Stylesheet
) -> Result<(), Error> where
impl WriteColor: WriteColor,
Trait Implementations
impl Render for Document
[src]
A Document is rendered by extending its nodes onto the original document.
fn render(self, into: Document) -> Document
[src]
fn into_fragment(self) -> Document
[src]
fn add<Right>(self, other: Right) -> Combine<Self, Right> where
Right: Render,
[src]
Right: Render,
impl Clone for Document
[src]
fn clone(&self) -> 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 Unpin for Document
impl Sync for Document
impl Send for Document
impl RefUnwindSafe for Document
impl UnwindSafe for Document
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Render for T where
T: Display,
[src]
T: Display,