pub fn option<T>(value: &Option<T>, default: &str) -> Stringwhere
T: ToString,
Expand description
A function which is usefull in conjuntion with
#[tabled(display)]
and #[tabled(display)]
.
It can be used with any Option
type.
You must provide a second argument which represents a value be printed in case of None
.
ยงExample
use tabled::{Tabled, Table, derive::display};
use tabled::assert::assert_table;
#[derive(Tabled)]
#[tabled(display(Option, "display::option", "Unknown"))]
pub struct ZKP<'a> {
application: &'a str,
state: Option<&'a str>
}
let data = vec![
ZKP { application: "Decentralized Identity", state: Some("Proved") },
ZKP { application: "Voting Systems", state: Some("Investigation") },
ZKP { application: "Privacy-Preserving Transactions", state: None },
];
let table = Table::new(data);
assert_table!(
table,
"+---------------------------------+---------------+"
"| application | state |"
"+---------------------------------+---------------+"
"| Decentralized Identity | Proved |"
"+---------------------------------+---------------+"
"| Voting Systems | Investigation |"
"+---------------------------------+---------------+"
"| Privacy-Preserving Transactions | Unknown |"
"+---------------------------------+---------------+"
);