use {Row, ToRow, Renderer};
use std;
#[derive(Clone, PartialEq, Debug)]
pub struct Table {
rows: Vec<RowOrSep>
}
#[derive(Clone, PartialEq, Debug)]
pub enum RowOrSep {
Row(Row),
Sep
}
impl RowOrSep {
pub fn row(&self) -> Option<&Row> {
match *self {
RowOrSep::Row(ref row) => Some(row),
_ => None
}
}
}
impl Table {
pub fn new() -> Table {
Table {
rows: Vec::new()
}
}
pub fn row<T: ToRow>(&mut self, row: T) -> &mut Table {
self.rows.push(RowOrSep::Row(row.to_row()));
self
}
pub fn sep(&mut self) -> &mut Table {
self.rows.push(RowOrSep::Sep);
self
}
pub fn rows(&self) -> &Vec<RowOrSep> {
&self.rows
}
pub fn write_to<T: std::io::Write>(&self, writer: &mut T) -> std::io::Result<()> {
Renderer::new(self).write_to(writer)
}
pub fn write_to_string(&self) -> String {
Renderer::new(self).write_to_string()
}
}