pub struct PoolTable { /* private fields */ }
Expand description
PoolTable
is a table which allows a greater set of possibilities for cell alignment.
It’s data is not aligned in any way by default.
It works similar to the main Table
by default.
use tabled::tables::PoolTable;
let data = vec![
vec!["Hello", "World", "!"],
vec!["Salve", "mondo", "!"],
vec!["Hola", "mundo", "!"],
];
let table = PoolTable::new(data).to_string();
assert_eq!(
table,
"+-------+-------+---+\n\
| Hello | World | ! |\n\
+-------+-------+---+\n\
| Salve | mondo | ! |\n\
+-------+-------+---+\n\
| Hola | mundo | ! |\n\
+-------+-------+---+"
)
But it allows you to have a different number of columns inside the rows.
use tabled::tables::PoolTable;
let data = vec![
vec!["Hello", "World", "!"],
vec!["Salve, mondo!"],
vec!["Hola", "mundo", "", "", "!"],
];
let table = PoolTable::new(data).to_string();
assert_eq!(
table,
"+---------+---------+----+\n\
| Hello | World | ! |\n\
+---------+---------+----+\n\
| Salve, mondo! |\n\
+------+-------+--+--+---+\n\
| Hola | mundo | | | ! |\n\
+------+-------+--+--+---+"
)
Notice that you also can build a custom table layout by using TableValue
.
use tabled::tables::{PoolTable, TableValue};
let message = "Hello\nWorld";
let data = TableValue::Column(vec![
TableValue::Row(vec![
TableValue::Column(vec![
TableValue::Cell(String::from(message)),
]),
TableValue::Column(vec![
TableValue::Cell(String::from(message)),
TableValue::Row(vec![
TableValue::Cell(String::from(message)),
TableValue::Cell(String::from(message)),
TableValue::Cell(String::from(message)),
])
]),
]),
TableValue::Cell(String::from(message)),
]);
let table = PoolTable::from(data).to_string();
assert_eq!(
table,
"+-------+-----------------------+\n\
| Hello | Hello |\n\
| World | World |\n\
| +-------+-------+-------+\n\
| | Hello | Hello | Hello |\n\
| | World | World | World |\n\
+-------+-------+-------+-------+\n\
| Hello |\n\
| World |\n\
+-------------------------------+"
)
Implementations§
Source§impl PoolTable
impl PoolTable
Sourcepub fn with<O>(&mut self, option: O) -> &mut Self
pub fn with<O>(&mut self, option: O) -> &mut Self
A is a generic function which applies options to the PoolTable
configuration.
Notice that it has a limited support of options.
use tabled::tables::PoolTable;
use tabled::settings::{Style, Padding};
let data = vec![
vec!["Hello", "World", "!"],
vec!["Salve", "mondo", "!"],
vec!["Hola", "mundo", "!"],
];
let table = PoolTable::new(data)
.with(Style::extended())
.with(Padding::zero())
.to_string();
assert_eq!(
table,
"╔═════╦═════╦═╗\n\
║Hello║World║!║\n\
╠═════╬═════╬═╣\n\
║Salve║mondo║!║\n\
╠═════╬═════╬═╣\n\
║Hola ║mundo║!║\n\
╚═════╩═════╩═╝"
)
Trait Implementations§
Source§impl From<TableValue> for PoolTable
impl From<TableValue> for PoolTable
Source§fn from(value: TableValue) -> Self
fn from(value: TableValue) -> Self
Converts to this type from the input type.
Source§impl Ord for PoolTable
impl Ord for PoolTable
Source§impl PartialOrd for PoolTable
impl PartialOrd for PoolTable
impl Eq for PoolTable
impl StructuralPartialEq for PoolTable
Auto Trait Implementations§
impl Freeze for PoolTable
impl RefUnwindSafe for PoolTable
impl Send for PoolTable
impl Sync for PoolTable
impl Unpin for PoolTable
impl UnwindSafe for PoolTable
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