pub struct Format;
Available on crate feature
std
only.Expand description
A formatting function of particular cells on a Table
.
Implementations§
source§impl Format
impl Format
sourcepub fn content<F>(f: F) -> FormatContent<F>
pub fn content<F>(f: F) -> FormatContent<F>
This function creates a new Format
instance, so
it can be used as a grid setting.
Example
use tabled::{Table, settings::{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::content(|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\
+-------+-------------+-----------+"
);
sourcepub fn positioned<F>(f: F) -> FormatContentPositioned<F>
pub fn positioned<F>(f: F) -> FormatContentPositioned<F>
This function creates a new FormatContentPositioned
, so
it can be used as a grid setting.
It’s different from Format::content
as it also provides a row and column index.
Example
use tabled::{Table, settings::{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::positioned(|_, (_, col)| col.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\
+---+---------+-------+"
);
sourcepub fn config<F>(f: F) -> FormatConfig<F>
pub fn config<F>(f: F) -> FormatConfig<F>
This function creates FormatConfig
function to modify a table config.
Example
use tabled::{
Table,
settings::{Format, object::Rows, Modify},
grid::config::ColoredConfig,
};
let data = vec![
(0, "Grodno", true),
(1, "Minsk", true),
(2, "Hamburg", false),
(3, "Brest", true),
];
let table = Table::new(&data)
.with(Format::config(|cfg: &mut ColoredConfig| cfg.set_justification((0,1).into(), '.')))
.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\
+-----+---------+-------+"
);
Trait Implementations§
Auto Trait Implementations§
impl RefUnwindSafe for Format
impl Send for Format
impl Sync for Format
impl Unpin for Format
impl UnwindSafe for Format
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more