Skip to content

Commit

Permalink
Update dependencies and fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
devashishdxt committed Oct 4, 2021
1 parent e3b4128 commit c9b57b5
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 12 deletions.
4 changes: 2 additions & 2 deletions cli-table-derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
proc-macro2 = "1.0.28"
syn = "1.0.75"
proc-macro2 = "1.0.29"
syn = "1.0.78"
quote = "1.0.9"

[lib]
Expand Down
2 changes: 1 addition & 1 deletion cli-table/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ path = "src/lib.rs"
cli-table-derive = { path = "../cli-table-derive", optional = true }
csv = { version = "1.1.6", optional = true }
termcolor = "1.1.2"
unicode-width = "0.1.8"
unicode-width = "0.1.9"

[features]
default = ["csv", "derive"]
Expand Down
74 changes: 74 additions & 0 deletions cli-table/src/dimension.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/// Dimensions of a cell
#[derive(Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq)]
pub struct CellDimension {
/// Width of a cell
pub width: usize,
/// Height of a cell
pub height: usize,
}

/// Dimensions of a row
#[derive(Debug, Default, Clone, Eq, PartialEq)]
pub struct RowDimension {
/// Widths of each cell of row
pub widths: Vec<usize>,
/// Height of row
pub height: usize,
}

/// Dimensions of a table
#[derive(Debug, Clone, Eq, PartialEq, Default)]
pub struct TableDimension {
/// Widths of each column of table
pub widths: Vec<usize>,
/// Height of each row of table
pub heights: Vec<usize>,
}

impl From<RowDimension> for Vec<CellDimension> {
fn from(row_dimension: RowDimension) -> Self {
let height = row_dimension.height;

row_dimension
.widths
.into_iter()
.map(|width| CellDimension { width, height })
.collect()
}
}

impl From<TableDimension> for Vec<RowDimension> {
fn from(table_dimension: TableDimension) -> Self {
let heights = table_dimension.heights;
let widths = table_dimension.widths;

heights
.into_iter()
.map(|height| RowDimension {
widths: widths.clone(),
height,
})
.collect()
}
}

/// Trait for calculating required dimensions for a type
pub trait RequiredDimension {
/// Type of dimension for given type
type Dimension;

/// Returns the required dimension
fn required_dimension(&self) -> Option<&Self::Dimension>;

/// Calculates the required dimension for a type and stores it in the type for future use
fn set_required_dimension(&mut self);
}

pub trait AvailableDimension: RequiredDimension {
fn available_dimension(&self) -> Option<&<Self as RequiredDimension>::Dimension>;

fn set_available_dimension(
&mut self,
available_dimension: <Self as RequiredDimension>::Dimension,
);
}
16 changes: 7 additions & 9 deletions cli-table/src/row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,29 +37,27 @@ impl RowStruct {
format: &TableFormat,
color_spec: &ColorSpec,
) -> Result<()> {
let buffers = self.buffers(&writer, dimension)?;
let buffers = self.buffers(writer, dimension)?;

for line in buffers.into_iter() {
print_vertical_line(&writer, format.border.left.as_ref(), &color_spec)?;
print_vertical_line(writer, format.border.left.as_ref(), color_spec)?;

let mut line_buffers = line.into_iter().peekable();

while let Some(buffer) = line_buffers.next() {
print_char(&writer, ' ', &color_spec)?;
print_char(writer, ' ', color_spec)?;
writer.print(&buffer)?;
print_char(&writer, ' ', &color_spec)?;
print_char(writer, ' ', color_spec)?;

match line_buffers.peek() {
Some(_) => {
print_vertical_line(&writer, format.separator.column.as_ref(), &color_spec)?
}
None => {
print_vertical_line(&writer, format.border.right.as_ref(), &color_spec)?
print_vertical_line(writer, format.separator.column.as_ref(), color_spec)?
}
None => print_vertical_line(writer, format.border.right.as_ref(), color_spec)?,
}
}

println_str(&writer, "", &color_spec)?;
println_str(writer, "", color_spec)?;
}

Ok(())
Expand Down

0 comments on commit c9b57b5

Please sign in to comment.