File: format_enum.rs

package info (click to toggle)
rust-tabled 0.18.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,408 kB
  • sloc: makefile: 4
file content (25 lines) | stat: -rw-r--r-- 721 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
//! This example demonstrates using the [attribute macro](https://doc.rust-lang.org/reference/procedural-macros.html#attribute-macros)
//! [`format`] to beatifuly castomize the resulting values, be used for table contraction.

use tabled::{Table, Tabled};

#[derive(Tabled)]
enum Vehicle {
    #[tabled(inline)]
    Car(#[tabled(format = "car->{}", rename = "cars")] String),
    #[tabled(inline)]
    Boat(#[tabled(format = "boat->{}", rename = "boats")] String),
}

fn main() {
    let data = [
        Vehicle::Car("bmw".into()),
        Vehicle::Car("audi".into()),
        Vehicle::Car("volkswagen".into()),
        Vehicle::Boat("ford".into()),
    ];

    let table = Table::new(data);

    println!("{table}");
}