Skip to content

Commit c9b57b5

Browse files
committed
Update dependencies and fix clippy warnings
1 parent e3b4128 commit c9b57b5

File tree

4 files changed

+84
-12
lines changed

4 files changed

+84
-12
lines changed

cli-table-derive/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ edition = "2018"
1515
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1616

1717
[dependencies]
18-
proc-macro2 = "1.0.28"
19-
syn = "1.0.75"
18+
proc-macro2 = "1.0.29"
19+
syn = "1.0.78"
2020
quote = "1.0.9"
2121

2222
[lib]

cli-table/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ path = "src/lib.rs"
2222
cli-table-derive = { path = "../cli-table-derive", optional = true }
2323
csv = { version = "1.1.6", optional = true }
2424
termcolor = "1.1.2"
25-
unicode-width = "0.1.8"
25+
unicode-width = "0.1.9"
2626

2727
[features]
2828
default = ["csv", "derive"]

cli-table/src/dimension.rs

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/// Dimensions of a cell
2+
#[derive(Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq)]
3+
pub struct CellDimension {
4+
/// Width of a cell
5+
pub width: usize,
6+
/// Height of a cell
7+
pub height: usize,
8+
}
9+
10+
/// Dimensions of a row
11+
#[derive(Debug, Default, Clone, Eq, PartialEq)]
12+
pub struct RowDimension {
13+
/// Widths of each cell of row
14+
pub widths: Vec<usize>,
15+
/// Height of row
16+
pub height: usize,
17+
}
18+
19+
/// Dimensions of a table
20+
#[derive(Debug, Clone, Eq, PartialEq, Default)]
21+
pub struct TableDimension {
22+
/// Widths of each column of table
23+
pub widths: Vec<usize>,
24+
/// Height of each row of table
25+
pub heights: Vec<usize>,
26+
}
27+
28+
impl From<RowDimension> for Vec<CellDimension> {
29+
fn from(row_dimension: RowDimension) -> Self {
30+
let height = row_dimension.height;
31+
32+
row_dimension
33+
.widths
34+
.into_iter()
35+
.map(|width| CellDimension { width, height })
36+
.collect()
37+
}
38+
}
39+
40+
impl From<TableDimension> for Vec<RowDimension> {
41+
fn from(table_dimension: TableDimension) -> Self {
42+
let heights = table_dimension.heights;
43+
let widths = table_dimension.widths;
44+
45+
heights
46+
.into_iter()
47+
.map(|height| RowDimension {
48+
widths: widths.clone(),
49+
height,
50+
})
51+
.collect()
52+
}
53+
}
54+
55+
/// Trait for calculating required dimensions for a type
56+
pub trait RequiredDimension {
57+
/// Type of dimension for given type
58+
type Dimension;
59+
60+
/// Returns the required dimension
61+
fn required_dimension(&self) -> Option<&Self::Dimension>;
62+
63+
/// Calculates the required dimension for a type and stores it in the type for future use
64+
fn set_required_dimension(&mut self);
65+
}
66+
67+
pub trait AvailableDimension: RequiredDimension {
68+
fn available_dimension(&self) -> Option<&<Self as RequiredDimension>::Dimension>;
69+
70+
fn set_available_dimension(
71+
&mut self,
72+
available_dimension: <Self as RequiredDimension>::Dimension,
73+
);
74+
}

cli-table/src/row.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,29 +37,27 @@ impl RowStruct {
3737
format: &TableFormat,
3838
color_spec: &ColorSpec,
3939
) -> Result<()> {
40-
let buffers = self.buffers(&writer, dimension)?;
40+
let buffers = self.buffers(writer, dimension)?;
4141

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

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

4747
while let Some(buffer) = line_buffers.next() {
48-
print_char(&writer, ' ', &color_spec)?;
48+
print_char(writer, ' ', color_spec)?;
4949
writer.print(&buffer)?;
50-
print_char(&writer, ' ', &color_spec)?;
50+
print_char(writer, ' ', color_spec)?;
5151

5252
match line_buffers.peek() {
5353
Some(_) => {
54-
print_vertical_line(&writer, format.separator.column.as_ref(), &color_spec)?
55-
}
56-
None => {
57-
print_vertical_line(&writer, format.border.right.as_ref(), &color_spec)?
54+
print_vertical_line(writer, format.separator.column.as_ref(), color_spec)?
5855
}
56+
None => print_vertical_line(writer, format.border.right.as_ref(), color_spec)?,
5957
}
6058
}
6159

62-
println_str(&writer, "", &color_spec)?;
60+
println_str(writer, "", color_spec)?;
6361
}
6462

6563
Ok(())

0 commit comments

Comments
 (0)