prettytable-rs
prettytable-rs copied to clipboard
Add trait bound ToString to Cell::new()/Cell::new_align()
After adding trait bound ToString
to Cell::new()/Cell::new_align()
, maybe it will be more convenient to construct a row from another type because it will be unnecessary to transform the content to &str
explicitly.
Codecov Report
Merging #94 into master will increase coverage by
0.08%
. The diff coverage is100%
.
@@ Coverage Diff @@
## master #94 +/- ##
==========================================
+ Coverage 84.05% 84.13% +0.08%
==========================================
Files 5 5
Lines 1179 1179
==========================================
+ Hits 991 992 +1
+ Misses 188 187 -1
Impacted Files | Coverage Δ | |
---|---|---|
src/cell.rs | 86.02% <100%> (+0.43%) |
:arrow_up: |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact)
,ø = not affected
,? = missing data
Powered by Codecov. Last update 6f01431...d6db8b8. Read the comment docs.
If I want to construct a Table
from a matrix
dynamically, I can implement it in the following code.
fn pretty_matrix(matrix: [[u8; 16]; 16]) -> Table {
let mut table = Table::new();
matrix.iter().for_each(|line| {
table.add_row(Row::new(
line.iter().map(|x| Cell::new(&x.to_string())).collect::<Vec<_>>(),
));
});
table
}
Now, the code becomes:
fn pretty_matrix(matrix: [[u8; 16]; 16]) -> Table {
let mut table = Table::new();
matrix.iter().for_each(|line| {
table.add_row(Row::new(
line.iter().map(|x| Cell::new(x)).collect::<Vec<_>>(),
));
});
table
}
@phsym ping
@phsym ping
@phsym ping
@iosmanthus cell!()
could convert expression to string automatically, but Cell::new
has no appropriate trait bounds.It is so strange.