use chrono::{Local, TimeZone}; use libjens::api::{Category, Meme, User}; use term_table::{row::Row, table_cell::TableCell, Table, TableBuilder, TableStyle}; /// returns an empty table with the correct format settings for lists pub fn list_table<'a>() -> Table<'a> { TableBuilder::new() .style(TableStyle::simple()) .separate_rows(false) .has_top_boarder(false) .has_bottom_boarder(false) .build() } pub trait AsTableRow { fn as_table_row(&self) -> term_table::row::Row; } impl AsTableRow for Category { fn as_table_row(&self) -> Row<'_> { Row::new(vec![TableCell::new(&self.id), TableCell::new(&self.name)]) } } impl AsTableRow for Meme { fn as_table_row(&self) -> Row<'_> { Row::new(vec![ TableCell::new(&self.link), TableCell::new(&self.category), TableCell::new(&self.user), TableCell::new(Local.timestamp(self.timestamp, 0).format("%F %R")), TableCell::new(&self.id), ]) } } impl AsTableRow for User { fn as_table_row(&self) -> Row<'_> { Row::new(vec![ TableCell::new(&self.name), TableCell::new(&self.get_id().map(String::as_ref).unwrap_or("[No ID]")), TableCell::new(&self.dayuploads), ]) } }