From 9fe5c714aa7dcf9bda501383a6ac3730b7288662 Mon Sep 17 00:00:00 2001 From: Maxim Zhiburt Date: Thu, 21 Nov 2024 22:14:15 +0300 Subject: [PATCH] tabled/ Rename Disable into Remove --- README.md | 18 +++++------- tabled/examples/disable.rs | 10 +++---- tabled/examples/show/src/main.rs | 24 ++++++++-------- tabled/src/lib.rs | 2 +- tabled/src/settings/disable/mod.rs | 40 +++++++++++++-------------- tabled/src/settings/mod.rs | 2 +- tabled/tests/settings/disable_test.rs | 18 ++++++------ tabled/tests/settings/extract_test.rs | 14 +++++----- 8 files changed, 62 insertions(+), 66 deletions(-) diff --git a/README.md b/README.md index 61876044..eea2769c 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ you can find more examples in the **[examples](/tabled/examples/)** folder. - [Height Increase](#height-increase) - [Height Limit](#height-limit) - [Rotate](#rotate) - - [Disable](#disable) + - [Remove](#remove) - [Extract](#extract) - [Header and Footer and Panel](#header-and-footer-and-panel) - [Merge](#merge) @@ -1106,19 +1106,15 @@ table.with(Rotate::Left); └──────────────┴────────────────────────┴───────────────────────────┴──────────────────────────┘ ``` -### Disable +### Remove -You can remove certain rows or columns from the table by `Disable`. +You can remove certain rows or columns from the table by `Remove`. ```rust -use tabled::settings::{ - object::{Columns, Rows}, - Disable, -}; +use tabled::settings::{object::{Columns, Rows}, Remove}; -table - .with(Disable::row(Rows::first())) - .with(Disable::column(Columns::single(2))); +table.with(Remove::row(Rows::first())); +table.with(Remove::column(Columns::single(2))); ``` If the above example be applied for a first example in a file it would look like this. @@ -1493,7 +1489,7 @@ struct Person { You can mark filds as hidden in which case they will be ignored and not be present on a sheet. -A similar effect could be achieved by the means of a `Disable` setting. +A similar effect could be achieved by the means of a [`Remove`](#remove). ```rust use tabled::Tabled; diff --git a/tabled/examples/disable.rs b/tabled/examples/disable.rs index 40fa4f5a..3357c499 100644 --- a/tabled/examples/disable.rs +++ b/tabled/examples/disable.rs @@ -1,11 +1,11 @@ -//! This example demonstrates using the [`Disable`] [`TableOption`] to remove specific +//! This example demonstrates using the [`Remove`] to remove specific //! cell data from a [`Table`] display. //! -//! * ⚠️ Using [`Disable`] in combination with other [`Style`] customizations may yield unexpected results. -//! It is safest to use [`Disable`] last in a chain of alterations. +//! * ⚠️ Using [`Remove`] in combination with other [`Style`] customizations may yield unexpected results. +//! It is safest to use [`Remove`] last in a chain of alterations. use tabled::{ - settings::{location::ByColumnName, Disable}, + settings::{location::ByColumnName, Remove}, Table, Tabled, }; @@ -36,7 +36,7 @@ fn main() { ]; let mut table = Table::new(data); - table.with(Disable::column(ByColumnName::new("is_active"))); + table.with(Remove::column(ByColumnName::new("is_active"))); println!("{table}"); } diff --git a/tabled/examples/show/src/main.rs b/tabled/examples/show/src/main.rs index 35a055ac..4ee3ccb8 100644 --- a/tabled/examples/show/src/main.rs +++ b/tabled/examples/show/src/main.rs @@ -27,7 +27,7 @@ use tabled::{ settings::{ object::{Columns, Object, Rows}, style::{Border, BorderColor, LineText, Style}, - Alignment, Color, Disable, Format, Highlight, Margin, Panel, Width, + Alignment, Color, Remove, Format, Highlight, Margin, Panel, Width, }, Table, Tabled, }; @@ -131,21 +131,21 @@ fn run(movies: &[Movie], debug: bool) { fn print_movies(p: &mut impl Printer, movies: &[Movie]) { #[rustfmt::skip] let create_titles_actions: Vec = vec![ - detached_action(|t| { t.with(Disable::row(Rows::new(1..))).with(Disable::column(Columns::new(1..))).with(Style::modern()); }), - detached_action(|t| { t.with(Disable::row(Rows::new(1..))).with(Disable::column(Columns::new(2..))).with(Style::modern()); }), - detached_action(|t| { t.with(Disable::row(Rows::new(1..))).with(Disable::column(Columns::new(3..))).with(Style::modern()); }), - detached_action(|t| { t.with(Disable::row(Rows::new(1..))).with(Disable::column(Columns::new(4..))).with(Style::modern()); }), - detached_action(|t| { t.with(Disable::row(Rows::new(1..))).with(Disable::column(Columns::new(5..))).with(Style::modern()); }), + detached_action(|t| { t.with(Remove::row(Rows::new(1..))).with(Remove::column(Columns::new(1..))).with(Style::modern()); }), + detached_action(|t| { t.with(Remove::row(Rows::new(1..))).with(Remove::column(Columns::new(2..))).with(Style::modern()); }), + detached_action(|t| { t.with(Remove::row(Rows::new(1..))).with(Remove::column(Columns::new(3..))).with(Style::modern()); }), + detached_action(|t| { t.with(Remove::row(Rows::new(1..))).with(Remove::column(Columns::new(4..))).with(Style::modern()); }), + detached_action(|t| { t.with(Remove::row(Rows::new(1..))).with(Remove::column(Columns::new(5..))).with(Style::modern()); }), ]; #[rustfmt::skip] let add_movies_actions: Vec = vec![ - detached_action(|t| { t.with(Disable::row(Rows::new(2..))).with(Style::modern()); }), - detached_action(|t| { t.with(Disable::row(Rows::new(3..))).with(Style::modern()); }), - detached_action(|t| { t.with(Disable::row(Rows::new(4..))).with(Style::modern()); }), - detached_action(|t| { t.with(Disable::row(Rows::new(5..))).with(Style::modern()); }), - detached_action(|t| { t.with(Disable::row(Rows::new(6..))).with(Style::modern()); }), - detached_action(|t| { t.with(Disable::row(Rows::new(7..))).with(Style::modern()); }), + detached_action(|t| { t.with(Remove::row(Rows::new(2..))).with(Style::modern()); }), + detached_action(|t| { t.with(Remove::row(Rows::new(3..))).with(Style::modern()); }), + detached_action(|t| { t.with(Remove::row(Rows::new(4..))).with(Style::modern()); }), + detached_action(|t| { t.with(Remove::row(Rows::new(5..))).with(Style::modern()); }), + detached_action(|t| { t.with(Remove::row(Rows::new(6..))).with(Style::modern()); }), + detached_action(|t| { t.with(Remove::row(Rows::new(7..))).with(Style::modern()); }), ]; #[rustfmt::skip] diff --git a/tabled/src/lib.rs b/tabled/src/lib.rs index b2835f5a..f5dfa3cf 100644 --- a/tabled/src/lib.rs +++ b/tabled/src/lib.rs @@ -336,7 +336,7 @@ pub use crate::{tabled::Tabled, tables::Table}; /// /// You can mark fields as hidden in which case they fill be ignored and not be present on a sheet. /// -/// A similar affect could be achieved by the means of a `Disable` setting. +/// A similar affect could be achieved by the means of a `Remove`. /// /// ```rust,no_run /// use tabled::Tabled; diff --git a/tabled/src/settings/disable/mod.rs b/tabled/src/settings/disable/mod.rs index bd927dca..ccee5c47 100644 --- a/tabled/src/settings/disable/mod.rs +++ b/tabled/src/settings/disable/mod.rs @@ -1,12 +1,12 @@ -//! This module contains a [`Disable`] structure which helps to +//! This module contains a [`Remove`] structure which helps to //! remove an etheir column or row from a [`Table`]. //! //! # Example //! //! ```rust,no_run -//! # use tabled::{Table, settings::{Disable, object::Rows}}; +//! # use tabled::{Table, settings::{Remove, object::Rows}}; //! # let data: Vec<&'static str> = Vec::new(); -//! let table = Table::new(&data).with(Disable::row(Rows::first())); +//! let table = Table::new(&data).with(Remove::row(Rows::first())); //! ``` //! //! [`Table`]: crate::Table @@ -18,22 +18,22 @@ use crate::{ settings::{location::Location, TableOption}, }; -/// Disable removes particular rows/columns from a [`Table`]. +/// Remove removes particular rows/columns from a [`Table`]. /// /// It tries to keeps track of style changes which may occur. /// But it's not guaranteed will be the way you would expect it to be. /// -/// Generally you should avoid use of [`Disable`] because it's a slow function and modifies the underlying records. +/// Generally you should avoid use of [`Remove`] because it's a slow function and modifies the underlying records. /// Providing correct data right away is better. /// /// # Example /// /// ``` -/// use tabled::{Table, settings::{Disable, object::Rows}}; +/// use tabled::{Table, settings::{Remove, object::Rows}}; /// /// let data = vec!["Hello", "World", "!!!"]; /// -/// let table = Table::new(data).with(Disable::row(Rows::new(1..2))).to_string(); +/// let table = Table::new(data).with(Remove::row(Rows::new(1..2))).to_string(); /// /// assert_eq!( /// table, @@ -49,13 +49,13 @@ use crate::{ /// ``` /// [`Table`]: crate::Table #[derive(Debug)] -pub struct Disable { +pub struct Remove { locator: L, target: PhantomData, } -impl Disable { - /// Disable columns. +impl Remove { + /// Remove columns. /// /// Available locators are: /// @@ -66,14 +66,14 @@ impl Disable { /// - [`ByColumnName`] /// /// ```rust - /// use tabled::{builder::Builder, settings::{Disable, location::ByColumnName, object::Columns}}; + /// use tabled::{builder::Builder, settings::{Remove, location::ByColumnName, object::Columns}}; /// /// let mut builder = Builder::default(); /// builder.push_record(["col1", "col2", "col3"]); /// builder.push_record(["Hello", "World", "1"]); /// /// let table = builder.build() - /// .with(Disable::column(ByColumnName::new("col3"))) + /// .with(Remove::column(ByColumnName::new("col3"))) /// .to_string(); /// /// assert_eq!( @@ -99,8 +99,8 @@ impl Disable { } } -impl Disable { - /// Disable rows. +impl Remove { + /// Remove rows. /// /// Available locators are: /// @@ -110,14 +110,14 @@ impl Disable { /// - [`LastRow`] /// /// ```rust - /// use tabled::{settings::{Disable, object::Rows}, builder::Builder}; + /// use tabled::{settings::{Remove, object::Rows}, builder::Builder}; /// /// let mut builder = Builder::default(); /// builder.push_record(["col1", "col2", "col3"]); /// builder.push_record(["Hello", "World", "1"]); /// /// let table = builder.build() - /// .with(Disable::row(Rows::first())) + /// .with(Remove::row(Rows::first())) /// .to_string(); /// /// assert_eq!( @@ -140,15 +140,15 @@ impl Disable { } } -/// A marker struct for [`Disable`]. +/// A marker struct for [`Remove`]. #[derive(Debug)] pub struct TargetRow; -/// A marker struct for [`Disable`]. +/// A marker struct for [`Remove`]. #[derive(Debug)] pub struct TargetColumn; -impl TableOption for Disable +impl TableOption for Remove where L: Location, R: Records + Resizable, @@ -171,7 +171,7 @@ where } } -impl TableOption for Disable +impl TableOption for Remove where L: Location, R: ExactRecords + Resizable, diff --git a/tabled/src/settings/mod.rs b/tabled/src/settings/mod.rs index 242a3518..52b31bcb 100644 --- a/tabled/src/settings/mod.rs +++ b/tabled/src/settings/mod.rs @@ -134,7 +134,7 @@ pub use self::{ pub use self::{ color::Color, concat::Concat, - disable::Disable, + disable::Remove, duplicate::Dup, format::Format, height::Height, diff --git a/tabled/tests/settings/disable_test.rs b/tabled/tests/settings/disable_test.rs index 50b8d6c8..bb49dd0e 100644 --- a/tabled/tests/settings/disable_test.rs +++ b/tabled/tests/settings/disable_test.rs @@ -4,7 +4,7 @@ use tabled::settings::{ location::ByColumnName, object::{Columns, Rows, Segment}, style::{HorizontalLine, Style}, - Alignment, Disable, Modify, + Alignment, Modify, Remove, }; use crate::matrix::Matrix; @@ -12,7 +12,7 @@ use testing_table::test_table; test_table!( disable_rows, - Matrix::new(3, 3).with(Disable::row(Rows::new(1..=2))), + Matrix::new(3, 3).with(Remove::row(Rows::new(1..=2))), "+---+----------+----------+----------+" "| N | column 0 | column 1 | column 2 |" "+---+----------+----------+----------+" @@ -22,7 +22,7 @@ test_table!( test_table!( disable_header, - Matrix::new(3, 3).with(Style::psql()).with(Disable::row(Rows::first())), + Matrix::new(3, 3).with(Style::psql()).with(Remove::row(Rows::first())), " 0 | 0-0 | 0-1 | 0-2 " "---+-----+-----+-----" " 1 | 1-0 | 1-1 | 1-2 " @@ -33,7 +33,7 @@ test_table!( disable_all_table_via_rows, Matrix::new(3, 3) .with(Style::psql()) - .with(Disable::row(Columns::new(..))), + .with(Remove::row(Columns::new(..))), "" ); @@ -41,7 +41,7 @@ test_table!( disable_header_with_new_styling, Matrix::new(3, 3) .with(Modify::new(Segment::all()).with(Alignment::left())) - .with(Disable::row(Rows::new(..1))) + .with(Remove::row(Rows::new(..1))) .with(Style::modern().remove_horizontal().horizontals([(1, HorizontalLine::inherit(Style::modern()))])), "┌───┬─────┬─────┬─────┐" "│ 0 │ 0-0 │ 0-1 │ 0-2 │" @@ -53,7 +53,7 @@ test_table!( test_table!( disable_columns, - Matrix::new(3, 3).with(Style::psql()).with(Disable::column(Columns::first())), + Matrix::new(3, 3).with(Style::psql()).with(Remove::column(Columns::first())), " column 0 | column 1 | column 2 " "----------+----------+----------" " 0-0 | 0-1 | 0-2 " @@ -64,8 +64,8 @@ test_table!( test_table!( disable_column_by_name, Matrix::new(3, 3).with(Style::psql()) - .with(Disable::column(ByColumnName::new("column 1"))) - .with(Disable::column(ByColumnName::new("column 3"))), + .with(Remove::column(ByColumnName::new("column 1"))) + .with(Remove::column(ByColumnName::new("column 3"))), " N | column 0 | column 2 " "---+----------+----------" " 0 | 0-0 | 0-2 " @@ -78,6 +78,6 @@ test_table!( Matrix::new(3, 3) .with(Style::psql()) .with(Modify::new(Segment::all()).with(Alignment::left())) - .with(Disable::column(Columns::new(..))), + .with(Remove::column(Columns::new(..))), "" ); diff --git a/tabled/tests/settings/extract_test.rs b/tabled/tests/settings/extract_test.rs index ce4697d7..9d2c42f8 100644 --- a/tabled/tests/settings/extract_test.rs +++ b/tabled/tests/settings/extract_test.rs @@ -4,7 +4,7 @@ use tabled::{ builder::Builder, settings::{ object::{Rows, Segment}, - Alignment, Disable, Extract, Format, Modify, Padding, + Alignment, Extract, Format, Modify, Padding, Remove, }, }; @@ -181,7 +181,7 @@ test_table!( test_table!( extract_inside_test, - Matrix::new(3, 3).with(Disable::row(Rows::first())).with(Extract::segment(1..2, 1..2)), + Matrix::new(3, 3).with(Remove::row(Rows::first())).with(Extract::segment(1..2, 1..2)), "+-----+" "| 1-0 |" "+-----+" @@ -189,7 +189,7 @@ test_table!( test_table!( extract_left_test, - Matrix::new(3, 3).with(Disable::row(Rows::first())).with(Extract::segment(.., ..1)), + Matrix::new(3, 3).with(Remove::row(Rows::first())).with(Extract::segment(.., ..1)), "+---+" "| 0 |" "+---+" @@ -201,7 +201,7 @@ test_table!( test_table!( extract_right_test, - Matrix::new(3, 3).with(Disable::row(Rows::first())).with(Extract::segment(.., 2..)), + Matrix::new(3, 3).with(Remove::row(Rows::first())).with(Extract::segment(.., 2..)), "+-----+-----+" "| 0-1 | 0-2 |" "+-----+-----+" @@ -213,7 +213,7 @@ test_table!( test_table!( extract_top_test, - Matrix::new(3, 3).with(Disable::row(Rows::first())).with(Extract::segment(..1, ..)), + Matrix::new(3, 3).with(Remove::row(Rows::first())).with(Extract::segment(..1, ..)), "+---+-----+-----+-----+" "| 0 | 0-0 | 0-1 | 0-2 |" "+---+-----+-----+-----+" @@ -221,7 +221,7 @@ test_table!( test_table!( extract_bottom_test, - Matrix::new(3, 3).with(Disable::row(Rows::first())).with(Extract::segment(2.., ..)), + Matrix::new(3, 3).with(Remove::row(Rows::first())).with(Extract::segment(2.., ..)), "+---+-----+-----+-----+" "| 2 | 2-0 | 2-1 | 2-2 |" "+---+-----+-----+-----+" @@ -230,7 +230,7 @@ test_table!( test_table!( extract_all_test, Matrix::new(3, 3) - .with(Disable::row(Rows::first())) + .with(Remove::row(Rows::first())) .with(Extract::segment(3.., 3..)), "" );