[−][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(
&self,
writer: &mut impl WriteColor,
stylesheet: &Stylesheet
) -> Result<(), Error>
[src]
&self,
writer: &mut impl WriteColor,
stylesheet: &Stylesheet
) -> Result<(), Error>
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<(), 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(
self,
writer: &mut impl WriteColor,
stylesheet: &Stylesheet
) -> Result<(), Error>
[src]
self,
writer: &mut impl WriteColor,
stylesheet: &Stylesheet
) -> Result<(), Error>
Trait Implementations
impl Clone for Document
[src]
impl Debug for Document
[src]
impl Render for Document
[src]
A Document is rendered by extending its nodes onto the original document.
Auto Trait Implementations
impl Send for Document
impl Sync for Document
impl Unpin for Document
impl UnwindSafe for Document
impl RefUnwindSafe for Document
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
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> 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,