Uh oh!
There was an error while loading. Please reload this page.
doc: improve Drain examples - #30272
Conversation
rust-highfive
commented
Dec 8, 2015
r? @aturon (rust_highfive has picked a reviewer for you, use r? to override) |
There was a problem hiding this comment.
The information about removal is good I think. You might otherwise think that only elements extracted from the iterator are removed from the String or Vec, or VecDeque.
There was a problem hiding this comment.
@bluss it's only the extracted elements that are removed
There was a problem hiding this comment.
No it's not, I implemented this for Vec and String.
There was a problem hiding this comment.
Not sure I understand you. Following does not panic:
letmut v = vec![1,2,3];assert_eq!(vec![3], v.drain(2..).collect::<Vec<_>>());assert_eq!(vec![1,2], v);
v.drain(..);assert!(v.is_empty());There was a problem hiding this comment.
ok, I mean that:
letmut v = vec![1,2,3];
v.drain(..).take(1).collect::<Vec<_>>();All elements in the range are removed even if only 1 element is taken ("extracted") from the iterator.
There was a problem hiding this comment.
Now I understand. But that is somewhat orthogonal isn't it... not worth mentioning in the summary. Also, the examples I added also demonstrate the fact you mention.
There was a problem hiding this comment.
It should be mentioned somewhere in the docs for the method IMO. It's something users have already wondered about, always best to say it explicitly.
bluss
commented
Dec 17, 2015
Thanks! @bors r+ |
bors
commented
Dec 17, 2015
📌 Commit 46e2296 has been approved by |
Second sentence actually repeats info from first sentence. "from start to end" also feels like it adds nothing. I also extended Vec::drain example.
bors
commented
Dec 18, 2015
bors
commented
Dec 18, 2015
⛄ The build was interrupted to prioritize another pull request. |
bors
commented
Dec 18, 2015
⚡ Previous build results for auto-linux-32-nopt-t, auto-linux-32-opt, auto-linux-64-debug-opt, auto-linux-64-nopt-t, auto-linux-64-opt, auto-linux-64-x-android-t, auto-linux-cross-opt, auto-linux-musl-64-opt, auto-mac-32-opt, auto-mac-64-nopt-t, auto-mac-64-opt, auto-win-gnu-32-nopt-t, auto-win-gnu-64-opt, auto-win-msvc-32-opt are reusable. Rebuilding only auto-win-gnu-32-opt, auto-win-gnu-64-nopt-t, auto-win-msvc-64-opt... |
Second sentence actually repeats info from first sentence. "from start to end" also feels like it adds nothing.
I also extended Vec::drain example.