zhiburt/tabled

Broken Docs for Alignment

mwlon opened this issue · 1 comments

mwlon commented

Copying exactly from the docs in version 0.12.2,

#[derive(Tabled)]
enum Domain {
    Security,
    Embedded,
    Frontend,
    Unknown,
}

#[derive(Tabled)]
struct Developer(#[tabled(rename = "name")] &'static str);
     
let data = vec![
    (Developer("Terri Kshlerin"), Domain::Embedded),
    (Developer("Catalina Dicki"), Domain::Security),
    (Developer("Jennie Schmeler"), Domain::Frontend),
    (Developer("Maxim Zhiburt"), Domain::Unknown),
];
     
let table = Table::new(data)
    .with(Style::psql())
    .with(Modify::new(Rows::new(1..).not(Columns::first())).with(Alignment::center()))
    .to_string();

assert_eq!(
    table,
    concat!(
        " name            | Security | Embedded | Frontend | Unknown \n",
        "-----------------+----------+----------+----------+---------\n",
        " Terri Kshlerin  |          |    +     |          |         \n",
        " Catalina Dicki  |    +     |          |          |         \n",
        " Jennie Schmeler |          |          |    +     |         \n",
        " Maxim Zhiburt   |          |          |          |    +    "
    )
);

This gives an error:

error[E0599]: no variant or associated item named `center` found for enum `std::fmt::Alignment` in the current scope
   --> bench/src/main.rs:541:77
    |
541 |     .with(Modify::new(Rows::new(1..).not(Columns::first())).with(Alignment::center()))
    |                                                                             ^^^^^^
    |                                                                             |
    |                                                                             variant or associated item not found in `Alignment`
    |                                                                             help: there is a variant with a similar name (notice the capitalization): `Center`

And even when I change it to the enum Alignment::Center, I get this error:

error[E0277]: the trait bound `std::fmt::Alignment: CellOption<VecRecords<CellInfo<String>>, ColoredConfig>` is not satisfied
   --> bench/src/main.rs:541:11
    |
541 |     .with(Modify::new(Rows::new(1..).not(Columns::first())).with(Alignment::Center))
    |      ---- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `CellOption<VecRecords<CellInfo<String>>, ColoredConfig>` is not implemented for `std::fmt::Alignment`
    |      |
    |      required by a bound introduced by this call
mwlon commented

Right after posting, I realized my mistake - tabled isn't using std::fmt::Alignment; it has its own. use tabled::settings::Alignment.