killercup / convey

A Rust create for outputting information and log messages for humans and machines
https://docs.rs/convey
Apache License 2.0
39 stars 5 forks source link

derive Render #6

Closed killercup closed 5 years ago

killercup commented 5 years ago

Offer a simple derive that used some default style and allows to do

#[derive(Serialize, RenderOutput)]
struct Foo { name: String, code: i32}

out.print(Foo { name: "hallo".into(), code: 42 })?;

The goal is to let people write even less code. This is an experiment, though, and only in addition to "manually" implemementing using the macros.

  1. [x] Create proc macro crate output_derive
  2. [x] Add a simple derive macro RenderOutput
    • [x] only works for structs for now
    • [x] generates the most trivial impl Render for $type
    • human output: just list all the fields separated by newlines
    • json output: same as render_json!();
  3. [ ] Add attributes to fields to add some formatting/converting.
killercup commented 5 years ago

Works, and the fuzzy requirement of "formatting attributes" should be tracked in another issue.