[−][src]Trait render_tree::prelude::Render
The Render trait defines a type that can be added to a Document.
It is defined for Node
, String
, &str
, and Document
.alloc
It is also defined for Option<T>
where T
is Render
, as well
as &T
where T
is both Render
and Clone
.
Generally speaking, if you need to make a type Render
, and it's
not one of your types, you can ergonomically make a newtype wrapper
for it.
For example, if you want to render std::time::Duration
:
#[macro_use] extern crate render_tree; extern crate termcolor; use render_tree::{Render, Document, Line, RenderComponent}; use std::time::Duration; use termcolor::StandardStream; struct RenderDuration(Duration); impl Render for RenderDuration { fn render(self, into: Document) -> Document { into.add(format!("{} seconds and {} nanos", self.0.as_secs(), self.0.subsec_nanos())) } } struct MessageContents { code: usize, header: String, body: String, duration: Duration, } fn message(args: MessageContents, into: Document) -> Document { into.render(tree! { <Line as { {args.code} ":" {args.header} "for" {RenderDuration(args.duration)} }> <Line as { {args.body} }> }) } fn main() -> std::io::Result<()> { let contents = MessageContents { code: 200, header: "Hello world".to_string(), body: "This is the body of the message".to_string(), duration: Duration::new(100, 1_000_000) }; let document = tree! { <message args={contents}> }; document.write() }
Required methods
fn render(self, into: Document) -> Document
Produce a new Document with self
added to the into
Document.
Provided methods
fn into_fragment(self) -> Document
fn add<Right: Render>(self, other: Right) -> Combine<Self, Right>
Implementors
impl Render for Node
[src]
impl Render for Node
A node is rendered by adding itself to the document
fn render(self, document: Document) -> Document | [src] |
fn into_fragment(self) -> Document | [src] |
fn add<Right: Render>(self, other: Right) -> Combine<Self, Right> | [src] |
impl Render for Document
[src]
impl Render for Document
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: Render>(self, other: Right) -> Combine<Self, Right> | [src] |
impl Render for Empty
[src]
impl Render for Empty
fn render(self, document: Document) -> Document | [src] |
fn into_fragment(self) -> Document | [src] |
fn add<Right: Render>(self, other: Right) -> Combine<Self, Right> | [src] |
impl<B: BlockComponent, Block: FnOnce(Document) -> Document> Render for CurriedBlockComponent<B, Block>
[src]
impl<B: BlockComponent, Block: FnOnce(Document) -> Document> Render for CurriedBlockComponent<B, Block>
fn render(self, document: Document) -> Document | [src] |
fn into_fragment(self) -> Document | [src] |
fn add<Right: Render>(self, other: Right) -> Combine<Self, Right> | [src] |
impl<B: IterBlockComponent, Block: FnMut(B::Item, Document) -> Document> Render for CurriedIterBlockComponent<B, Block>
[src]
impl<B: IterBlockComponent, Block: FnMut(B::Item, Document) -> Document> Render for CurriedIterBlockComponent<B, Block>
fn render(self, document: Document) -> Document | [src] |
fn into_fragment(self) -> Document | [src] |
fn add<Right: Render>(self, other: Right) -> Combine<Self, Right> | [src] |
impl<B: OnceBlockComponent, Block: FnOnce(B::Item, Document) -> Document> Render for CurriedOnceBlockComponent<B, Block>
[src]
impl<B: OnceBlockComponent, Block: FnOnce(B::Item, Document) -> Document> Render for CurriedOnceBlockComponent<B, Block>
fn render(self, document: Document) -> Document | [src] |
fn into_fragment(self) -> Document | [src] |
fn add<Right: Render>(self, other: Right) -> Combine<Self, Right> | [src] |
impl<F> Render for OnceBlock<F> where
F: FnOnce(Document) -> Document,
[src]
impl<F> Render for OnceBlock<F> where
F: FnOnce(Document) -> Document,
fn render(self, into: Document) -> Document | [src] |
fn into_fragment(self) -> Document | [src] |
fn add<Right: Render>(self, other: Right) -> Combine<Self, Right> | [src] |
impl<Left: Render, Right: Render> Render for Combine<Left, Right>
[src]
impl<Left: Render, Right: Render> Render for Combine<Left, Right>
fn render(self, into: Document) -> Document | [src] |
fn into_fragment(self) -> Document | [src] |
fn add<Right: Render>(self, other: Right) -> Combine<Self, Right> | [src] |
impl<T: Display> Render for T
[src]
impl<T: Display> Render for T