Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add trait bound ToString to Cell::new()/Cell::new_align() #94

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

iosmanthus
Copy link

@iosmanthus iosmanthus commented Oct 21, 2018

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
Copy link

codecov bot commented Oct 21, 2018

Codecov Report

Merging #94 into master will increase coverage by 0.08%.
The diff coverage is 100%.

Impacted file tree graph

@@            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%) ⬆️

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.

@iosmanthus
Copy link
Author

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
}

Copy link
Owner

@phsym phsym left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems legit. Thanks

@phsym phsym self-assigned this Dec 17, 2018
@iosmanthus
Copy link
Author

@phsym ping

2 similar comments
@iosmanthus
Copy link
Author

@phsym ping

@Jedsek
Copy link

Jedsek commented Aug 21, 2022

@phsym ping

@Jedsek
Copy link

Jedsek commented Aug 21, 2022

@iosmanthus cell!() could convert expression to string automatically, but Cell::new has no appropriate trait bounds.It is so strange.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants