pub fn bool<T, F>(value: &bool, on_true: T, on_false: F) -> String
Expand description
A function which is usefull in conjuntion with
#[tabled(display)]
and #[tabled(display)]
.
It can be used with a bool
type.
You must provide 2 argumnts which will be display
for true and false case correspondingly.
ยงExample
use tabled::{Tabled, Table, assert::assert_table, derive::display};
#[derive(Tabled)]
#[tabled(display(bool, "display::bool", "Got", 0))]
pub struct State {
name: &'static str,
working: bool,
closed: bool,
}
let data = vec![
State { name: "work", working: true, closed: false },
State { name: "stop", working: false, closed: false },
State { name: "closed", working: false, closed: true },
];
let table = Table::new(data);
assert_table!(
table,
"+--------+---------+--------+"
"| name | working | closed |"
"+--------+---------+--------+"
"| work | Got | 0 |"
"+--------+---------+--------+"
"| stop | 0 | 0 |"
"+--------+---------+--------+"
"| closed | 0 | Got |"
"+--------+---------+--------+"
);