Changed constructors.

This commit is contained in:
Gerrit Viljoen 2020-04-01 20:52:36 +02:00
parent 1f210fb3a0
commit 4b8c1f5c31
2 changed files with 15 additions and 14 deletions

View File

@ -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
}
}

View File

@ -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
}