zhiburt / tabled

An easy to use library for pretty print tables of Rust structs and enums.
MIT License
1.94k stars 77 forks source link

Add a new `Tabled` attribute `format = ""` as a shortcut for a `display_with` #396

Closed zhiburt closed 5 months ago

zhiburt commented 5 months ago

I guess it's make sense to do. To reduce a boilerplate for common simple cases.

#[derive(Tabled)]
struct Motorcycle {
  weight: usize,
  #[tabled(format = "{} cc")]
  cc: usize,
}

I think a 2nd version could exist, to being able to use a self as argument.

#[derive(Tabled)]
struct Motorcycle {
  weight: usize,
  #[tabled(format("{}/{} cc/kg", self.cc, self.weight))]
  cc: usize,
}
thomassimmer commented 5 months ago

Hello,

I started working on this here: https://github.com/thomassimmer/tabled/tree/tabled-attribute-format Just need to make tests work for enums. Could you assign this to me ?

Cheers, Thomas

zhiburt commented 5 months ago

Hi @thomassimmer

Thanks

If you have any question please ping me.

But overall it shall be very very very similar to display_with implementation. Don't be frightened by quite bad quality code at tabled_derive/src/lib.rs. (too many arguments too functions etc.) (I will try to solve it sooon hopefully)

Take care.

zhiburt commented 5 months ago

closed by #398