pub struct Document { /* private fields */ }
Expand description
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(())
}
Implementations§
Source§impl Document
impl Document
pub fn debug_write( &self, writer: &mut impl WriteColor, stylesheet: &Stylesheet, ) -> Result<(), Error>
Source§impl Document
impl Document
pub fn empty() -> Document
pub fn with(renderable: impl Render) -> Document
pub fn add(self, renderable: impl Render) -> Document
pub fn write(self) -> Result<(), Error>
pub fn to_string(self) -> Result<String, Error>
pub fn write_styled(self, stylesheet: &Stylesheet) -> Result<(), Error>
pub fn write_with( self, writer: &mut impl WriteColor, stylesheet: &Stylesheet, ) -> Result<(), Error>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Document
impl RefUnwindSafe for Document
impl Send for Document
impl Sync for Document
impl Unpin for Document
impl UnwindSafe for Document
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)