mirror of
https://gitlab.com/arnekeller/ascii-table.git
synced 2024-12-04 21:49:08 +00:00
Changed constructors.
This commit is contained in:
parent
1f210fb3a0
commit
4b8c1f5c31
23
src/lib.rs
23
src/lib.rs
@ -60,13 +60,6 @@ pub struct AsciiTable {
|
||||
pub columns: BTreeMap<usize, Column>
|
||||
}
|
||||
|
||||
impl AsciiTable {
|
||||
|
||||
pub fn new(width: usize, columns: BTreeMap<usize, Column>) -> Self { // TODO: remove
|
||||
Self { width, columns }
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for AsciiTable {
|
||||
|
||||
fn default() -> Self {
|
||||
@ -77,7 +70,7 @@ impl Default for AsciiTable {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, Eq, PartialEq)]
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
pub struct Column {
|
||||
pub header: String,
|
||||
pub align: Align
|
||||
@ -85,9 +78,17 @@ pub struct Column {
|
||||
|
||||
impl Column {
|
||||
|
||||
pub fn new<T>(header: T, align: Align) -> Self // TODO: remove
|
||||
where T: AsRef<str> {
|
||||
Self { header: header.as_ref().to_string(), align }
|
||||
pub fn with_header(header: &str) -> Self {
|
||||
let mut result = Self::default();
|
||||
result.header = header.into();
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Column {
|
||||
|
||||
fn default() -> Self {
|
||||
DEFAULT_COLUMN
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,9 +22,9 @@ use std::fmt::Display;
|
||||
|
||||
fn cube_config() -> AsciiTable {
|
||||
let mut result = AsciiTable::default();
|
||||
result.columns.insert(0, Column::new("a", Left));
|
||||
result.columns.insert(1, Column::new("b", Left));
|
||||
result.columns.insert(2, Column::new("c", Left));
|
||||
result.columns.insert(0, Column::with_header("a"));
|
||||
result.columns.insert(1, Column::with_header("b"));
|
||||
result.columns.insert(2, Column::with_header("c"));
|
||||
result
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user