Function debug

Source
pub fn debug<T>(value: &T) -> String
where T: Debug,
Expand description

A function which is usefull in conjuntion with #[tabled(display)] and #[tabled(display)].

It can be used with any type which implements a Debug. So rather then std::fmt::Display usage we will be using a debug implementation.

use tabled::{Tabled, Table, derive::display};
use tabled::assert::assert_table;

#[derive(Tabled)]
#[tabled(display(Option, "display::debug"))]
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,
    r#"+---------------------------------+-----------------------+"#
    r#"| application                     | state                 |"#
    r#"+---------------------------------+-----------------------+"#
    r#"| Decentralized Identity          | Some("Proved")        |"#
    r#"+---------------------------------+-----------------------+"#
    r#"| Voting Systems                  | Some("Investigation") |"#
    r#"+---------------------------------+-----------------------+"#
    r#"| Privacy-Preserving Transactions | None                  |"#
    r#"+---------------------------------+-----------------------+"#
);