-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Replace iterator-based construction of collections by Into<T>
#91861
Replace iterator-based construction of collections by Into<T>
#91861
Conversation
r? @yaahc (rust-highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
3ba1ff7
to
d2642cb
Compare
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.
Thanks for the PR! These look like great improvements (especially the BTreeMap one, I was pleasantly surprised that works!), however (as I commented inline) I think it would be better to use into
rather than from
where possible.
@@ -2547,7 +2547,7 @@ impl<T, A: Allocator> VecDeque<T, A> { | |||
/// ``` | |||
/// use std::collections::VecDeque; | |||
/// | |||
/// let deque: VecDeque<_> = vec![0, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55].into(); | |||
/// let deque = VecDeque::from([0, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]); |
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.
The docs recommend using into
over from
, so could we keep using into
in these cases, but drop the vec!
? (And replace the various iterator constructs with into
rather than from
too)
I wouldn't mind replacing |
That's a good question! Since it is a big question and somewhat orthogonal to the goal of this PR, I would work around it here and discuss separately (i.e., open an issue or PR if you are interested). For this PR, I would leave the from/into part of each example and just remove the iterator-ish boilerplate. |
☔ The latest upstream changes (presumably #92070) made this pull request unmergeable. Please resolve the merge conflicts. |
d2642cb
to
0577401
Compare
From<[T; N]>
Into<T>
This comment has been minimized.
This comment has been minimized.
0577401
to
8936659
Compare
@nrc, I've updated the PR. Now, the intermediate Let me know if there's anything else that could be improved. |
lgtm, thanks for the changes @juniorbassani ! @yaahc could you give an official review please? |
Looks great to me, thank you very much, both of you! @bors r+ |
📌 Commit 8936659 has been approved by |
…askrgr Rollup of 7 pull requests Successful merges: - rust-lang#90247 (Improve Duration::try_from_secs_f32/64 accuracy by directly processing exponent and mantissa) - rust-lang#91861 (Replace iterator-based construction of collections by `Into<T>`) - rust-lang#92098 (add OpenBSD platform-support page) - rust-lang#92134 (Add x86_64-pc-windows-msvc linker-plugin-lto instructions) - rust-lang#92256 (Improve selection errors for `~const` trait bounds) - rust-lang#92778 (fs: Use readdir() instead of readdir_r() on Linux and Android) - rust-lang#93338 (Update minifier crate version to 0.0.42) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
This commits ports one small part of rust-lang/rust#91861. The main change that PR made to `binary_heap.rs` was to replace vectors with arrays in the examples. We do *not* port such changes as they require Rust 1.56.0, which is greater than this crate's current MSRV. However, it also simplified the setup in the example of `BinaryHeap::append()`, and we repeat that here only with vectors instead of arrays.
This change is ported from rust-lang/rust#91861. Also finish porting rust-lang/rust#84111, partially ported here in sekineh#34, by including the example of constructing a binary heap from an array.
Just a few quality of life improvements in the doc examples. I also removed some
Vec
s in favor of arrays.