cli_table/
title.rs

1use crate::{Row, RowStruct, Table, TableStruct};
2
3/// Trait for getting title row of a struct
4#[cfg_attr(
5    any(docsrs, feature = "doc"),
6    doc(cfg(any(feature = "title", feature = "derive")))
7)]
8pub trait Title {
9    /// Returns title row of a struct
10    fn title() -> RowStruct;
11}
12
13/// Trait for creating a table with titles at the top
14#[cfg_attr(
15    any(docsrs, feature = "doc"),
16    doc(cfg(any(feature = "title", feature = "derive")))
17)]
18pub trait WithTitle {
19    /// Creates a table with title at the top
20    fn with_title(self) -> TableStruct;
21}
22
23impl<'a, T, R> WithTitle for T
24where
25    T: IntoIterator<Item = &'a R>,
26    R: Title + 'static,
27    &'a R: Row,
28{
29    fn with_title(self) -> TableStruct {
30        let table = self.table();
31        let title = R::title();
32        table.title(title)
33    }
34}