diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-07 05:48:48 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-07 05:48:48 +0000 |
commit | ef24de24a82fe681581cc130f342363c47c0969a (patch) | |
tree | 0d494f7e1a38b95c92426f58fe6eaa877303a86c /vendor/tabled/examples/format.rs | |
parent | Releasing progress-linux version 1.74.1+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-ef24de24a82fe681581cc130f342363c47c0969a.tar.xz rustc-ef24de24a82fe681581cc130f342363c47c0969a.zip |
Merging upstream version 1.75.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/tabled/examples/format.rs')
-rw-r--r-- | vendor/tabled/examples/format.rs | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/vendor/tabled/examples/format.rs b/vendor/tabled/examples/format.rs new file mode 100644 index 000000000..7dc4bddb2 --- /dev/null +++ b/vendor/tabled/examples/format.rs @@ -0,0 +1,56 @@ +//! This example demonstrates using the [`Format`] [`CellOption`] factory to alter +//! the cells of a [`Table`]. +//! +//! * Note how [`Format::content()`] gives access to the respective cell content for replacement. +//! And [`Format::positioned()`] additionally provides the index coordinates of that cell. +//! +//! * Note how the [std] [`format!`] macro is used to update the values of the affected cells. + +use tabled::{ + settings::{ + object::{Columns, Object, Rows}, + Format, Modify, Style, + }, + Table, Tabled, +}; + +#[derive(Tabled)] +struct Commit { + id: &'static str, + header: &'static str, + message: &'static str, +} + +fn main() { + let data = [ + Commit { + header: "bypass open-source transmitter", + message: "index neural panel", + id: "8ae4e8957caeaa467acbce963701e227af00a1c7", + }, + Commit { + header: "program online alarm", + message: "copy bluetooth card", + id: "48c76de71bd685486d97dc8f4f05aa6fcc0c3f86", + }, + Commit { + header: "CSV", + message: "reboot mobile capacitor", + id: "6ffc2a2796229fc7bf59471ad907f58b897005d0", + }, + ]; + + let table = Table::new(data) + .with(Style::psql()) + .with( + Modify::new(Rows::first()) + .with(Format::positioned(|_, (_, column)| column.to_string())), + ) + .with( + Modify::new(Columns::first().not(Rows::first())) + .with(Format::content(|s| format!("{s}..."))), + ) + .to_string(); + + println!("{table}"); +} |