Repository: zhiburt/tabled
Pull request #103 (2022-03-25 13:59:38)

Refactored format.rs module


Patch:
diff --git a/README.md b/README.md
index fbee604..511369b 100644
--- a/README.md
+++ b/README.md
@@ -317,8 +317,8 @@ The `Format` function provides an interface for a modification of cells.
 use tabled::{Table, Modify, Format, object::{Rows, Columns}};
 
 Table::new(&data)
-    .with(Modify::new(Rows::first()).with(Format(|s| format!("Head {}", s))));
-    .with(Modify::new(Columns::new(1..=2)).with(Format(|s| format!("<< {} >>", s))))
+    .with(Modify::new(Rows::first()).with(Format::new(|s| format!("Head {}", s))));
+    .with(Modify::new(Columns::new(1..=2)).with(Format::new(|s| format!("<< {} >>", s))))
 ```
 
 It's also possible to use functions with signature `Fn(&str) -> String` as a formatter.
@@ -333,11 +333,6 @@ Table::new(&data)
 
 IMPORTANT: you may need to specify type in your lambda otherwise compiler may be disagreed to work :)
 
-There's 2 more Format modifiers. You can find more imformation about theire usage in the documentation.
-
-- `FormatFrom` - Uses `Vec` elements as new content.
-- `FormatWithIndex` - Like `Format` but with `row` and `column` index in lambda.
-
 ### Padding
 
 The `Padding` structure provides an interface for a left, right, top and bottom padding of cells.
@@ -723,9 +718,9 @@ use tabled::{Table, Modify, Style, Format, object::Columns};
 
 Table::new(&data)
     .with(Style::psql())
-    .with(Modify::new(Columns::single(0)).with(Format(|s| s.red().to_string())))
-    .with(Modify::new(Columns::single(1)).with(Format(|s| s.blue().to_string())))
-    .with(Modify::new(Columns::new(2..)).with(Format(|s| s.green().to_string())));
+    .with(Modify::new(Columns::single(0)).with(Format::new(|s| s.red().to_string())))
+    .with(Modify::new(Columns::single(1)).with(Format::new(|s| s.blue().to_string())))
+    .with(Modify::new(Columns::new(2..)).with(Format::new(|s| s.green().to_string())));
 ```
 
 ![carbon-2](https://user-images.githubusercontent.com/20165848/120526301-b95efc80-c3e1-11eb-8779-0ec48894463b.png)
diff --git a/examples/color.rs b/examples/color.rs
index 638a494..b6073e5 100644
--- a/examples/color.rs
+++ b/examples/color.rs
@@ -54,10 +54,10 @@ fn main() {
         .with(Style::psql())
         .with(Modify::new(Rows::first()).with(Alignment::center_horizontal()))
         .with(Modify::new(Rows::new(1..)).with(Alignment::left()))
-        .with(Modify::new(Columns::single(1)).with(Format(|s| s.blue().to_string())))
+        .with(Modify::new(Columns::single(1)).with(Format::new(|s| s.blue().to_string())))
         .with(
             Modify::new(Columns::single(0).and(Columns::new(2..)))
-                .with(Format(|s| s.red().to_string())),
+                .with(Format::new(|s| s.red().to_string())),
         );
 
     println!("{}", table);
diff --git a/examples/extract.rs b/examples/extract.rs
index 6d6a144..0185094 100644
--- a/examples/extract.rs
+++ b/examples/extract.rs
@@ -68,7 +68,7 @@ fn main() {
     println!("Refinished segment");
     let table = table
         .with(Style::modern())
-        .with(Modify::new(Columns::new(1..)).with(Format(|s| {
+        .with(Modify::new(Columns::new(1..)).with(Format::new(|s| {
             if s == "Outstanding" {
                 format!("+{}+", s)
             } else {
diff --git a/examples/format.rs b/examples/format.rs
index df723cd..80d7c58 100644
--- a/examples/format.rs
+++ b/examples/format.rs
@@ -1,11 +1,11 @@
 //! The example can be run by this command
 //! `cargo run --example format`
 //!
-//! The example shows a usage of Format/FormatWithIndex/FormatFrom.
+//! The example shows a usage of [tabled::Format]/[tabled::FormatWithIndex].
 
 use tabled::{
     object::{Columns, Object, Rows},
-    Format, FormatFrom, FormatWithIndex, Modify, Style, Table, Tabled,
+    Format, Modify, Style, Table, Tabled,
 };
 
 #[derive(Tabled)]
@@ -36,14 +36,12 @@ fn main() {
 
     let table = Table::new(&data)
         .with(Style::github_markdown())
-        .with(Modify::new(Rows::new(..1)).with(FormatWithIndex(|_, _, column| column.to_string())))
         .with(
-            Modify::new(Rows::new(1..2).not(Columns::new(..1)))
-                .with(FormatFrom(vec!["qwe", "asd"])),
+            Modify::new(Rows::new(..1))
+                .with(Format::with_index(|_, (_, column)| column.to_string())),
         )
         .with(
-            Modify::new(Columns::new(..1).not(Rows::new(..1)))
-                .with(Format(|s| format!("{}...", s))),
+            Modify::new(Columns::new(..1).not(Rows::new(..1))).with(|s: &str| format!("{}...", s)),
         );
 
     println!("{}", table);
diff --git a/src/extract.rs b/src/extract.rs
index d456a58..5b615d9 100644
--- a/src/extract.rs
+++ b/src/extract.rs
@@ -19,7 +19,7 @@ use crate::TableOption;
 /// ];
 ///
 /// let table = Table::new(&data)
-///                .with(Modify::new(Rows::new(1..)).with(Format(|s| format!(": {} :", s))))
+///                .with(Modify::new(Rows::new(1..)).with(Format::new(|s| format!(": {} :", s))))
 ///                .with(Extract::segment(1..=2, 1..))
 ///                .to_string();
 ///
diff --git a/src/formating.rs b/src/formating.rs
index 66d8e6e..581cd4d 100644
--- a/src/formating.rs
+++ b/src/formating.rs
@@ -1,172 +1,163 @@
 use crate::CellOption;
 use papergrid::{Entity, Grid, Settings};
 
-/// Formatting of particular cells on a [Grid].
-///
-/// # Example
-///
-/// ```
-/// use tabled::{Table, Format, object::Rows, Modify};
-///
-/// let data = vec![
-///     (0, "Grodno", true),
-///     (1, "Minsk", true),
-///     (2, "Hamburg", false),
-///     (3, "Brest", true),
-/// ];
-///
-/// let table = Table::new(&data)
-///                .with(Modify::new(Rows::new(1..)).with(Format(|s| format!(": {} :", s))))
-///                .to_string();
-///
-/// assert_eq!(table, "+-------+-------------+-----------+\n\
-///                    |  i32  |    &str     |   bool    |\n\
-///                    +-------+-------------+-----------+\n\
-///                    | : 0 : | : Grodno :  | : true :  |\n\
-///                    +-------+-------------+-----------+\n\
-///                    | : 1 : |  : Minsk :  | : true :  |\n\
-///                    +-------+-------------+-----------+\n\
-///                    | : 2 : | : Hamburg : | : false : |\n\
-///                    +-------+-------------+-----------+\n\
-///                    | : 3 : |  : Brest :  | : true :  |\n\
-///                    +-------+-------------+-----------+\n");
-/// ```
-///
-pub struct Format<F: Fn(&str) -> String>(pub F);
+/// Formatting function of particular cells on a [Grid].
+pub struct Format<F> {
+    f: F,
+}
 
-impl<F: Fn(&str) -> String> CellOption for Format<F> {
-    fn change_cell(&mut self, grid: &mut Grid, row: usize, column: usize) {
-        let content = grid.get_cell_content(row, column);
-        let content = (self.0)(content);
-        grid.set(&Entity::Cell(row, column), Settings::new().text(content))
+impl Format<()> {
+    /// This function creates a new [Format] instance, so
+    /// it can be used as a grid setting.
+    ///
+    /// # Example
+    ///
+    /// ```
+    /// use tabled::{Table, Format, object::Rows, Modify};
+    ///
+    /// let data = vec![
+    ///     (0, "Grodno", true),
+    ///     (1, "Minsk", true),
+    ///     (2, "Hamburg", false),
+    ///     (3, "Brest", true),
+    /// ];
+    ///
+    /// let table = Table::new(&data)
+    ///                .with(Modify::new(Rows::new(1..)).with(Format::new(|s| format!(": {} :", s))))
+    ///                .to_string();
+    ///
+    /// assert_eq!(table, "+-------+-------------+-----------+\n\
+    ///                    |  i32  |    &str     |   bool    |\n\
+    ///                    +-------+-------------+-----------+\n\
+    ///                    | : 0 : | : Grodno :  | : true :  |\n\
+    ///                    +-------+-------------+-----------+\n\
+    ///                    | : 1 : |  : Minsk :  | : true :  |\n\
+    ///                    +-------+-------------+-----------+\n\
+    ///                    | : 2 : | : Hamburg : | : false : |\n\
+    ///                    +-------+-------------+-----------+\n\
+    ///                    | : 3 : |  : Brest :  | : true :  |\n\
+    ///                    +-------+-------------+-----------+\n");
+    /// ```
+    ///
+    pub fn new<F>(f: F) -> Format<F>
+    where
+        F: FnMut(&str) -> String,
+    {
+        Format { f }
+    }
+
+    /// This function creates a new [FormatWithIndex], so
+    /// it can be used as a grid setting.
+    ///
+    /// It's different from [Self::new] that it also provides a row and column index.
+    ///
+    /// # Example
+    ///
+    /// ```
+    /// use tabled::{Table, Format, object::Rows, Modify};
+    ///
+    /// let data = vec![
+    ///     (0, "Grodno", true),
+    ///     (1, "Minsk", true),
+    ///     (2, "Hamburg", false),
+    ///     (3, "Brest", true),
+    /// ];
+    ///
+    /// let table = Table::new(&data)
+    ///                .with(Modify::new(Rows::single(0)).with(Format::with_index(|_, (_, column)| column.to_string())))
+    ///                .to_string();
+    ///
+    /// assert_eq!(table, "+---+---------+-------+\n\
+    ///                    | 0 |    1    |   2   |\n\
+    ///                    +---+---------+-------+\n\
+    ///                    | 0 | Grodno  | true  |\n\
+    ///                    +---+---------+-------+\n\
+    ///                    | 1 |  Minsk  | true  |\n\
+    ///                    +---+---------+-------+\n\
+    ///                    | 2 | Hamburg | false |\n\
+    ///                    +---+---------+-------+\n\
+    ///                    | 3 |  Brest  | true  |\n\
+    ///                    +---+---------+-------+\n");
+    /// ```
+    pub fn with_index<F>(f: F) -> FormatWithIndex<F>
+    where
+        F: FnMut(&str, (usize, usize)) -> String,
+    {
+        FormatWithIndex::new(f)
+    }
+
+    /// Multiline a helper function for changing multiline content of cell.
+    /// Using this formatting applied for all rows not to a string as a whole.
+    ///
+    /// ```rust,no_run
+    /// use tabled::{Table, Format, object::Full, Modify};
+    /// let data: Vec<&'static str> = Vec::new();
+    /// let table = Table::new(&data)
+    ///     .with(Modify::new(Full).with(Format::multiline(|s| format!("{}", s))))
+    ///     .to_string();
+    /// ```
+    pub fn multiline<F>(f: F) -> Format<impl Fn(&str) -> String>
+    where
+        F: Fn(&str) -> String,
+    {
+        let closure = move |s: &str| {
+            let mut v = Vec::new();
+            for line in s.lines() {
+                v.push(f(line));
+            }
+
+            v.join("\n")
+        };
+
+        Format::new(closure)
     }
 }
 
-impl<F> CellOption for F
+impl<F> CellOption for Format<F>
 where
-    F: for<'r> FnMut(&'r str) -> String,
+    F: FnMut(&str) -> String,
 {
     fn change_cell(&mut self, grid: &mut Grid, row: usize, column: usize) {
         let content = grid.get_cell_content(row, column);
-        let content = (self)(content);
+        let content = (self.f)(content);
         grid.set(&Entity::Cell(row, column), Settings::new().text(content))
     }
 }
 
-/// Multiline a helper function for changing multiline content of cell.
-/// Using this formatting applied for all rows not to a string as a whole.
+/// FormatWithIndex is like a [Format] an abstraction over a function you can use agains a cell.
 ///
-/// ```rust,no_run
-/// use tabled::{Table, Format, multiline, object::Full, Modify};
-/// let data: Vec<&'static str> = Vec::new();
-/// let table = Table::new(&data)
-///     .with(Modify::new(Full).with(Format(multiline(|s| format!("{}", s)))))
-///     .to_string();
-/// ```
-pub fn multiline<F>(f: F) -> Box<dyn Fn(&str) -> String>
-where
-    F: Fn(&str) -> String + 'static,
-{
-    let closure = move |s: &str| {
-        let mut v = Vec::new();
-        for line in s.lines() {
-            v.push(f(line));
-        }
-
-        v.join("\n")
-    };
-
-    Box::new(closure)
+/// It differerent from Format that it provides a row and column index.
+pub struct FormatWithIndex<F> {
+    f: F,
 }
 
-/// FormatFrom repeatedly uses first possible element
-/// from given array unless there's any elements.
-///
-/// # Example
-///
-/// ```
-/// use tabled::{Table, FormatFrom, object::Rows, Modify};
-///
-/// let data = vec![
-///     (0, "Grodno", true),
-///     (1, "Minsk", true),
-///     (2, "Hamburg", false),
-///     (3, "Brest", true),
-/// ];
-///
-/// let table = Table::new(&data)
-///                .with(Modify::new(Rows::single(0)).with(FormatFrom(vec!["N", "City", "is in Belarus"])))
-///                .to_string();
-///
-/// assert_eq!(table, "+---+---------+---------------+\n\
-///                    | N |  City   | is in Belarus |\n\
-///                    +---+---------+---------------+\n\
-///                    | 0 | Grodno  |     true      |\n\
-///                    +---+---------+---------------+\n\
-///                    | 1 |  Minsk  |     true      |\n\
-///                    +---+---------+---------------+\n\
-///                    | 2 | Hamburg |     false     |\n\
-///                    +---+---------+---------------+\n\
-///                    | 3 |  Brest  |     true      |\n\
-///                    +---+---------+---------------+\n");
-/// ```
-pub struct FormatFrom<A>(pub Vec<A>)
+impl<F> FormatWithIndex<F>
 where
-    A: Into<String>;
+    F: FnMut(&str, (usize, usize)) -> String,
+{
+    pub fn new(f: F) -> Self {
+        Self { f }
+    }
+}
 
-impl<A> CellOption for FormatFrom<A>
+impl<F> CellOption for FormatWithIndex<F>
 where
-    A: Into<String>,
+    F: FnMut(&str, (usize, usize)) -> String,
 {
     fn change_cell(&mut self, grid: &mut Grid, row: usize, column: usize) {
-        if !self.0.is_empty() {
-            let new_content = self.0.remove(0).into();
-            grid.set(
-                &Entity::Cell(row, column),
-                Settings::new().text(new_content),
-            )
-        }
+        let content = grid.get_cell_content(row, column);
+        let content = (self.f)(content, (row, column));
+        grid.set(&Entity::Cell(row, column), Settings::new().text(content))
     }
 }
 
-/// FormatWithIndex is like a [Format].
-/// But it also provides a row and column index.
-///
-/// # Example
-///
-/// ```
-/// use tabled::{Table, FormatWithIndex, object::Rows, Modify};
-///
-/// let data = vec![
-///     (0, "Grodno", true),
-///     (1, "Minsk", true),
-///     (2, "Hamburg", false),
-///     (3, "Brest", true),
-/// ];
-///
-/// let table = Table::new(&data)
-///                .with(Modify::new(Rows::single(0))
-///                     .with(FormatWithIndex(|_, _, column| column.to_string())))
-///                .to_string();
-///
-/// assert_eq!(table, "+---+---------+-------+\n\
-///                    | 0 |    1    |   2   |\n\
-///                    +---+---------+-------+\n\
-///                    | 0 | Grodno  | true  |\n\
-///                    +---+---------+-------+\n\
-///                    | 1 |  Minsk  | true  |\n\
-///                    +---+---------+-------+\n\
-///                    | 2 | Hamburg | false |\n\
-///                    +---+---------+-------+\n\
-///                    | 3 |  Brest  | true  |\n\
-///                    +---+---------+-------+\n");
-/// ```
-pub struct FormatWithIndex<F: FnMut(&str, usize, usize) -> String>(pub F);
-
-impl<F: FnMut(&str, usize, usize) -> String> CellOption for FormatWithIndex<F> {
+impl<F> CellOption for F
+where
+    F: FnMut(&str) -> String,
+{
     fn change_cell(&mut self, grid: &mut Grid, row: usize, column: usize) {
         let content = grid.get_cell_content(row, column);
-        let content = (self.0)(content, row, column);
+        let content = (self)(content);
         grid.set(&Entity::Cell(row, column), Settings::new().text(content))
     }
 }


Test patch:
diff --git a/tests/extract_test.rs b/tests/extract_test.rs
index ec7bf11..c4239bb 100644
--- a/tests/extract_test.rs
+++ b/tests/extract_test.rs
@@ -9,7 +9,7 @@ fn extract_segment_full_test() {
     let table = Table::new(&data)
         .with(Modify::new(Full).with(Alignment::left()))
         .with(Modify::new(Full).with(Padding::new(3, 1, 0, 0)))
-        .with(Modify::new(Full).with(Format(|s| format!("[{}]", s))))
+        .with(Modify::new(Full).with(Format::new(|s| format!("[{}]", s))))
         .with(Extract::segment(.., ..))
         .to_string();
 
@@ -34,7 +34,7 @@ fn extract_segment_skip_top_row_test() {
     let table = Table::new(&data)
         .with(Modify::new(Full).with(Alignment::left()))
         .with(Modify::new(Full).with(Padding::new(3, 1, 0, 0)))
-        .with(Modify::new(Full).with(Format(|s| format!("[{}]", s))))
+        .with(Modify::new(Full).with(Format::new(|s| format!("[{}]", s))))
         .with(Extract::segment(1.., ..))
         .to_string();
 
@@ -57,7 +57,7 @@ fn extract_segment_skip_left_col_test() {
     let table = Table::new(&data)
         .with(Modify::new(Full).with(Alignment::left()))
         .with(Modify::new(Full).with(Padding::new(3, 1, 0, 0)))
-        .with(Modify::new(Full).with(Format(|s| format!("[{}]", s))))
+        .with(Modify::new(Full).with(Format::new(|s| format!("[{}]", s))))
         .with(Extract::segment(.., 1..))
         .to_string();
 
@@ -82,7 +82,7 @@ fn extract_segment_bottom_right_square_test() {
     let table = Table::new(&data)
         .with(Modify::new(Full).with(Alignment::left()))
         .with(Modify::new(Full).with(Padding::new(3, 1, 0, 0)))
-        .with(Modify::new(Full).with(Format(|s| format!("[{}]", s))))
+        .with(Modify::new(Full).with(Format::new(|s| format!("[{}]", s))))
         .with(Extract::segment(2.., 2..))
         .to_string();
 
@@ -103,7 +103,7 @@ fn extract_segment_middle_section_test() {
     let table = Table::new(&data)
         .with(Modify::new(Full).with(Alignment::left()))
         .with(Modify::new(Full).with(Padding::new(3, 1, 0, 0)))
-        .with(Modify::new(Full).with(Format(|s| format!("[{}]", s))))
+        .with(Modify::new(Full).with(Format::new(|s| format!("[{}]", s))))
         .with(Extract::segment(1..3, 1..))
         .to_string();
 
@@ -124,7 +124,7 @@ fn extract_segment_empty_test() {
     let table = Table::new(&data)
         .with(Modify::new(Full).with(Alignment::left()))
         .with(Modify::new(Full).with(Padding::new(3, 1, 0, 0)))
-        .with(Modify::new(Full).with(Format(|s| format!("[{}]", s))))
+        .with(Modify::new(Full).with(Format::new(|s| format!("[{}]", s))))
         .with(Extract::segment(1..1, 1..1))
         .to_string();
 
@@ -137,7 +137,7 @@ fn extract_rows_full_test() {
     let table = Table::new(&data)
         .with(Modify::new(Full).with(Alignment::left()))
         .with(Modify::new(Full).with(Padding::new(3, 1, 0, 0)))
-        .with(Modify::new(Full).with(Format(|s| format!("[{}]", s))))
+        .with(Modify::new(Full).with(Format::new(|s| format!("[{}]", s))))
         .with(Extract::rows(..))
         .to_string();
 
@@ -162,7 +162,7 @@ fn extract_rows_empty_test() {
     let table = Table::new(&data)
         .with(Modify::new(Full).with(Alignment::left()))
         .with(Modify::new(Full).with(Padding::new(3, 1, 0, 0)))
-        .with(Modify::new(Full).with(Format(|s| format!("[{}]", s))))
+        .with(Modify::new(Full).with(Format::new(|s| format!("[{}]", s))))
         .with(Extract::rows(0..0))
         .to_string();
 
@@ -175,7 +175,7 @@ fn extract_rows_partial_view_test() {
     let table = Table::new(&data)
         .with(Modify::new(Full).with(Alignment::left()))
         .with(Modify::new(Full).with(Padding::new(3, 1, 0, 0)))
-        .with(Modify::new(Full).with(Format(|s| format!("[{}]", s))))
+        .with(Modify::new(Full).with(Format::new(|s| format!("[{}]", s))))
         .with(Extract::rows(0..=2))
         .to_string();
 
@@ -198,7 +198,7 @@ fn extract_columns_full_test() {
     let table = Table::new(&data)
         .with(Modify::new(Full).with(Alignment::left()))
         .with(Modify::new(Full).with(Padding::new(3, 1, 0, 0)))
-        .with(Modify::new(Full).with(Format(|s| format!("[{}]", s))))
+        .with(Modify::new(Full).with(Format::new(|s| format!("[{}]", s))))
         .with(Extract::columns(..))
         .to_string();
 
@@ -223,7 +223,7 @@ fn extract_columns_empty_test() {
     let table = Table::new(&data)
         .with(Modify::new(Full).with(Alignment::left()))
         .with(Modify::new(Full).with(Padding::new(3, 1, 0, 0)))
-        .with(Modify::new(Full).with(Format(|s| format!("[{}]", s))))
+        .with(Modify::new(Full).with(Format::new(|s| format!("[{}]", s))))
         .with(Extract::columns(0..0))
         .to_string();
 
@@ -236,7 +236,7 @@ fn extract_columns_partial_view_test() {
     let table = Table::new(&data)
         .with(Modify::new(Full).with(Alignment::left()))
         .with(Modify::new(Full).with(Padding::new(3, 1, 0, 0)))
-        .with(Modify::new(Full).with(Format(|s| format!("[{}]", s))))
+        .with(Modify::new(Full).with(Format::new(|s| format!("[{}]", s))))
         .with(Extract::columns(0..2))
         .to_string();
 
diff --git a/tests/format_test.rs b/tests/format_test.rs
index 6ec21df..d606979 100644
--- a/tests/format_test.rs
+++ b/tests/format_test.rs
@@ -1,8 +1,7 @@
 use crate::util::create_vector;
 use tabled::{
-    multiline,
     object::{Cell, Columns, Full, Object, Rows},
-    Alignment, Format, FormatFrom, FormatWithIndex, Modify, Padding, Style, Table,
+    Alignment, Format, Modify, Padding, Style, Table,
 };
 
 mod util;
@@ -11,7 +10,7 @@ mod util;
 fn formatting_full_test() {
     let data = create_vector::<3, 3>();
     let table = Table::new(&data)
-        .with(Modify::new(Full).with(Format(|s| format!("[{}]", s))))
+        .with(Modify::new(Full).with(Format::new(|s| format!("[{}]", s))))
         .to_string();
 
     let expected = concat!(
@@ -34,7 +33,7 @@ fn formatting_head_test() {
     let data = create_vector::<3, 3>();
     let table = Table::new(&data)
         .with(Style::github_markdown())
-        .with(Modify::new(Rows::first()).with(Format(|s| format!(":{}", s))))
+        .with(Modify::new(Rows::first()).with(Format::new(|s| format!(":{}", s))))
         .to_string();
 
     let expected = concat!(
@@ -53,7 +52,7 @@ fn formatting_row_test() {
     let data = create_vector::<3, 3>();
     let table = Table::new(&data)
         .with(Style::psql())
-        .with(Modify::new(Rows::new(1..)).with(Format(|s| format!("<{}>", s))))
+        .with(Modify::new(Rows::new(1..)).with(Format::new(|s| format!("<{}>", s))))
         .to_string();
 
     let expected = concat!(
@@ -72,7 +71,7 @@ fn formatting_column_test() {
     let data = create_vector::<3, 3>();
     let table = Table::new(&data)
         .with(Style::psql())
-        .with(Modify::new(Columns::single(0)).with(Format(|s| format!("(x) {}", s))))
+        .with(Modify::new(Columns::single(0)).with(Format::new(|s| format!("(x) {}", s))))
         .to_string();
     let expected = concat!(
         " (x) N | column 0 | column 1 | column 2 \n",
@@ -93,7 +92,7 @@ fn formatting_multiline_test() {
 
     let table = Table::new(&data)
         .with(Style::psql())
-        .with(Modify::new(Full).with(Format(multiline(|s| format!("(x) {}", s)))))
+        .with(Modify::new(Full).with(Format::multiline(|s| format!("(x) {}", s))))
         .to_string();
 
     let expected = concat!(
@@ -120,9 +119,9 @@ fn formatting_cell_test() {
     let data = create_vector::<3, 3>();
     let table = Table::new(&data)
         .with(Style::psql())
-        .with(Modify::new(Cell(0, 0)).with(Format(|s| format!("(x) {}", s))))
-        .with(Modify::new(Cell(0, 1)).with(Format(|s| format!("(x) {}", s))))
-        .with(Modify::new(Cell(0, 2)).with(Format(|s| format!("(x) {}", s))))
+        .with(Modify::new(Cell(0, 0)).with(Format::new(|s| format!("(x) {}", s))))
+        .with(Modify::new(Cell(0, 1)).with(Format::new(|s| format!("(x) {}", s))))
+        .with(Modify::new(Cell(0, 2)).with(Format::new(|s| format!("(x) {}", s))))
         .to_string();
 
     let expected = concat!(
@@ -143,7 +142,7 @@ fn formatting_and_combination_test() {
         .with(Style::psql())
         .with(
             Modify::new(Columns::single(0).and(Rows::single(0)))
-                .with(Format(|s| format!("(x) {}", s))),
+                .with(Format::new(|s| format!("(x) {}", s))),
         )
         .to_string();
 
@@ -165,7 +164,7 @@ fn formatting_not_combination_test() {
         .with(Style::psql())
         .with(
             Modify::new(Columns::single(0).and(Rows::single(0)).not(Cell(0, 0)))
-                .with(Format(|s| format!("(x) {}", s))),
+                .with(Format::new(|s| format!("(x) {}", s))),
         )
         .to_string();
 
@@ -218,36 +217,13 @@ fn formatting_using_function_test() {
     assert_eq!(table, expected);
 }
 
-#[test]
-fn format_from() {
-    let data = create_vector::<3, 3>();
-    let table = Table::new(&data)
-        .with(Style::github_markdown())
-        .with(Modify::new(Rows::first()).with(FormatFrom(vec![
-            "Header Name 1",
-            "Header Name 2",
-            "Header Name 3",
-        ])))
-        .to_string();
-
-    let expected = concat!(
-        "| Header Name 1 | Header Name 2 | Header Name 3 | column 2 |\n",
-        "|---------------+---------------+---------------+----------|\n",
-        "|       0       |      0-0      |      0-1      |   0-2    |\n",
-        "|       1       |      1-0      |      1-1      |   1-2    |\n",
-        "|       2       |      2-0      |      2-1      |   2-2    |\n",
-    );
-
-    assert_eq!(table, expected);
-}
-
 #[test]
 fn format_with_index() {
     let data = create_vector::<3, 3>();
     let table = Table::new(&data)
         .with(Style::github_markdown())
         .with(
-            Modify::new(Rows::first()).with(FormatWithIndex(|a, b, c| match (b, c) {
+            Modify::new(Rows::first()).with(Format::with_index(|a, (b, c)| match (b, c) {
                 (0, 0) => "(0, 0)".to_string(),
                 (0, 1) => "(0, 1)".to_string(),
                 (0, 2) => "(0, 2)".to_string(),
@@ -280,9 +256,9 @@ mod color {
             .with(Style::psql())
             .with(
                 Modify::new(Columns::new(..1).and(Columns::new(2..)))
-                    .with(Format(|s| s.red().to_string())),
+                    .with(Format::new(|s| s.red().to_string())),
             )
-            .with(Modify::new(Columns::new(1..2)).with(Format(|s| s.blue().to_string())))
+            .with(Modify::new(Columns::new(1..2)).with(Format::new(|s| s.blue().to_string())))
             .to_string();
 
         let expected = concat!(
@@ -305,9 +281,9 @@ mod color {
 
         let table = Table::new(&data)
             .with(Style::psql())
-            .with(Modify::new(Columns::new(..1)).with(Format(multiline(|s| s.red().to_string()))))
-            .with(Modify::new(Columns::new(1..2)).with(Format(multiline(|s| s.blue().to_string()))))
-            .with(Modify::new(Columns::new(2..)).with(Format(multiline(|s| s.green().to_string()))))
+            .with(Modify::new(Columns::new(..1)).with(Format::multiline(|s| s.red().to_string())))
+            .with(Modify::new(Columns::new(1..2)).with(Format::multiline(|s| s.blue().to_string())))
+            .with(Modify::new(Columns::new(2..)).with(Format::multiline(|s| s.green().to_string())))
             .to_string();
 
         let expected = concat!(
@@ -336,7 +312,7 @@ fn format_doesnt_change_padding() {
     let table = Table::new(&data)
         .with(Modify::new(Full).with(Alignment::left()))
         .with(Modify::new(Full).with(Padding::new(3, 1, 0, 0)))
-        .with(Modify::new(Full).with(Format(|s| format!("[{}]", s))))
+        .with(Modify::new(Full).with(Format::new(|s| format!("[{}]", s))))
         .to_string();
 
     let expected = concat!(