tokio-rs / valuable

MIT License
185 stars 19 forks source link

feat(DeriveAttribute) Implement derive macro attribute for format #131

Open johnhurt opened 2 weeks ago

johnhurt commented 2 weeks ago

Build on the newly-introduced derive-attribute framework to allow fields in structs to be written to the final value as a formatted string instead of their actual value. This allows for types that don't (and can't or won't) implement Valuable to be included in the value

taiki-e commented 1 week ago

Thanks for the PR!

johnhurt commented 5 days ago

Ooooooh, I see what you mean. Let me tackle those one at a time

  1. That doesn't seem like a good thing. I didn't think about the ability to leak things out with a format. I will change this from #[valuable(format = "{}")] to just #[valuable(debug)] to avoid
  2. There doesn't seem to be a way around allocating to do what I'm trying to do. Even to complete #4 I think would require allocation :-/ ... Would you be open to the idea of adding an opt-in alloc feature that would gate the #[valuable(debug)] attribute?
taiki-e commented 8 hours ago

Adding Debug/Display (or Debugable/Displayable mentioned in https://github.com/tokio-rs/valuable/issues/43#issuecomment-854111197) variant to valuable::Value and then adding #[valuable(debug)]/#[valuable(display)] that pass the field as Value::Debug/Value::Display to derive seem to good idea to me.