Macro convey::render_for_humans
source · macro_rules! render_for_humans {
($this:ident -> []) => { ... };
($self:ident -> [$($item:expr,)*]) => { ... };
}
Expand description
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 {
// we need to explicitly pass `self` here, similar to regular methods
render_for_humans!(self -> [
// compose output components
text("Important notice from "),
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(())
}