Macro convey::render_for_humans[][src]

macro_rules! render_for_humans {
    ($this:ident -> []) => { ... };
    ($self:ident -> [$($item:expr,)*]) => { ... };
}

Shorthand for writing the render_for_humans method of the Render trait

Examples

#[macro_use] extern crate convey;
#[macro_use] extern crate serde_derive;

use convey::{components::{text, newline}, Render};

#[derive(Serialize)]
struct Message {
    author: String,
    body: String,
}

impl Render for Message {
    // because `self` is a keyword, we need to use something else
    render_for_humans!(self -> [
        // compose output components
        text("Important notice from "),
        // refer to struct fields using the name you specified above
        text(&self.author), newline(),
        text("> "), text(&self.body),
    ]);

    // see `json` module
    render_json!();
}

fn main() -> Result<(), convey::Error> {
    let mut out = convey::new().add_target(convey::human::stdout()?);
    out.print(Message { author: "Pascal".into(), body: "Lorem ipsum dolor".into() })?;
    Ok(())
}