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/derive/rename_all.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/derive/rename_all.rs')
-rw-r--r-- | vendor/tabled/examples/derive/rename_all.rs | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/vendor/tabled/examples/derive/rename_all.rs b/vendor/tabled/examples/derive/rename_all.rs new file mode 100644 index 000000000..cd408e5ba --- /dev/null +++ b/vendor/tabled/examples/derive/rename_all.rs @@ -0,0 +1,56 @@ +//! This example demonstrates using the [attribute macro](https://doc.rust-lang.org/reference/procedural-macros.html#attribute-macros) +//! [`rename_all`] to apply table-wide header formatting in a [`Table`] display. +//! +//! * Supported formatting rules include: +//! * 'camelCase' +//! * 'kabab-case' +//! * 'PascalCase' +//! * 'SCREAMING_SNAKE_CASE' +//! * 'snake_case' +//! * 'lowercase' +//! * 'UPPERCASE' +//! * 'verbatim' + +use tabled::{Table, Tabled}; + +#[derive(Tabled)] +#[tabled(rename_all = "camelCase")] +struct Country { + name: &'static str, + capital_city: &'static str, + surface_area_km2: f32, + #[tabled(rename_all = "kebab-case")] + national_currency: &'static str, + #[tabled(rename_all = "kebab-case")] + national_currency_short: &'static str, +} + +impl Country { + fn new( + name: &'static str, + national_currency: &'static str, + national_currency_short: &'static str, + capital_city: &'static str, + surface_area_km2: f32, + ) -> Self { + Self { + name, + national_currency, + national_currency_short, + capital_city, + surface_area_km2, + } + } +} + +fn main() { + let data = [ + Country::new("Afghanistan", "Afghani", "AFN", "Kabul", 652867.0), + Country::new("Angola", "Kwanza", "AOA", "Luanda", 1246700.0), + Country::new("Canada", "Canadian Dollar", "CAD", "Ottawa", 9984670.0), + ]; + + let table = Table::new(data); + + println!("{table}"); +} |