[][src]Trait render_tree::RenderComponent

pub trait RenderComponent<'args> {
    type Args;
    fn render(&self, args: Self::Args, into: Document) -> Document;
}

This trait defines a renderable entity with arguments. Types that implement RenderComponent can be packaged up together with their arguments in a Component, and the Component is renderable.

Example

#[macro_use]
extern crate render_tree;
extern crate termcolor;
use render_tree::{Document, Line, Render, RenderComponent};
use termcolor::StandardStream;

struct MessageContents {
    code: usize,
    header: String,
    body: String,
}

fn Message(args: MessageContents, into: Document) -> Document {
    into.add(tree! {
        <Line as {
            {args.code} ":" {args.header}
        }>

        <Line as {
            {args.body}
        }>
    })
}

fn main() -> std::io::Result<()> {
    let message = MessageContents {
        code: 200,
        header: "Hello world".to_string(),
        body: "This is the body of the message".to_string()
    };

    let document = tree! { <Message args={message}> };

    document.write()
}

Associated Types

type Args

Loading content...

Required methods

fn render(&self, args: Self::Args, into: Document) -> Document

Loading content...

Implementors

Loading content...