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()
.add(Line(
"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(())
}
A Document is rendered by extending its nodes onto the original
document.
Produce a new Document with self
added to the into
Document.
Performs copy-assignment from source
. Read more
Formats the value using the given formatter. Read more
Creates owned data from borrowed data, usually by cloning. Read more
🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static