-
-
Notifications
You must be signed in to change notification settings - Fork 346
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
feat(table): Implement FromIterator for widgets::Row #755
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #755 +/- ##
=======================================
- Coverage 92.3% 92.3% -0.1%
=======================================
Files 55 55
Lines 14844 14840 -4
=======================================
- Hits 13707 13703 -4
Misses 1137 1137 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neat! The only thing I'd suggest adding would be some docs to the Row
type so there's some example to point people in this direction.
Happy to take this as is though if you don't want to spend the time of docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like that too, very good idea!
Oh and your commit needs to be signed for us to merge if that's not too much to ask.
https://github.com/ratatui-org/ratatui/blob/main/CONTRIBUTING.md#sign-your-commits has some info on this. |
c2705f4
to
89b3e72
Compare
Sounds good, and I've updated the docstring for
No problem, and it should now be signed. |
89b3e72
to
b6ba189
Compare
The `Row::new` constructor accepts a single argument that implements `IntoIterator`. This commit adds an implementation of `FromIterator`, as a thin wrapper around `Row::new`. This allows `.collect::<Row>()` to be used at the end of an iterator chain, rather than wrapping the entire iterator chain in `Row::new`. Examples in `examples/table.rs` that used an intermediate variable for the cell iterator have been updated to instead collect directly into a `Row`. Examples that have an explicit `vec![cell1, ..., cellN]` have been kept as-is.
b6ba189
to
7c346f0
Compare
Thanks for this PR :) |
I wonder if it makes sense to do this for any other types |
I took a brief look at
|
Cool. Do you want to raise a couple of issues for these? |
A follow-up from ratatui#755, allowing any iterator whose item is convertible into `Line` to be collected into `Tabs`.
A follow-up from ratatui#755, allowing any iterator whose item is convertible into `ListItem` to be collected into a `List`.
A follow-up from ratatui#755, allowing any iterator whose item is convertible into `Row` to be collected into a `Table`.
A follow-up from ratatui#755, allowing any iterator whose item is convertible into `Line` to be collected into `Tabs`. In addition, where previously `Tabs::new` required a `Vec`, it can now accept any object that implements `IntoIterator` with an item type implementing `Into<Line>`.
A follow-up from ratatui#755, allowing any iterator whose item is convertible into `Line` to be collected into `Tabs`. In addition, where previously `Tabs::new` required a `Vec`, it can now accept any object that implements `IntoIterator` with an item type implementing `Into<Line>`. BREAKING CHANGE: Calls to `Tabs::new()` whose argument is collected from an iterator will no longer compile. For example, `Tabs::new(["a","b"].into_iter().collect())` will no longer compile, because the return type of `.collect()` can no longer be inferred to be a `Vec<_>`.
A follow-up from ratatui#755, allowing any iterator whose item is convertible into `Line` to be collected into `Tabs`. In addition, where previously `Tabs::new` required a `Vec`, it can now accept any object that implements `IntoIterator` with an item type implementing `Into<Line>`. BREAKING CHANGE: Calls to `Tabs::new()` whose argument is collected from an iterator will no longer compile. For example, `Tabs::new(["a","b"].into_iter().collect())` will no longer compile, because the return type of `.collect()` can no longer be inferred to be a `Vec<_>`.
A follow-up from ratatui#755, allowing any iterator whose item is convertible into `Row` to be collected into a `Table`. Where previously, `Table::new` accepted `IntoIterator<Item = Row>`, it now accepts `IntoIterator<Item: Into<Row>>`. BREAKING CHANGE: The compiler can no longer infer the element type of the container passed to `Table::new()`. For example, `Table::new(vec![], widths)` will no longer compile, as the type of `vec![]` can no longer be inferred.
The
Row::new
constructor accepts a single argument that implementsIntoIterator
. This commit adds an implementation ofFromIterator
, as a thin wrapper aroundRow::new
. This allows.collect::<Row>()
to be used at the end of an iterator chain, rather than wrapping the entire iterator chain inRow::new
.Examples in
examples/table.rs
that used an intermediate variable for the cell iterator have been updated to instead collect directly into aRow
. Examples that have an explicitvec![cell1, ..., cellN]
have been kept as-is.