-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Confusing examples in Vec::extend_from_within #104762
Labels
A-docs
Area: Documentation for any part of the project, including the compiler, standard library, and tools
Comments
@rustbot claim |
This was referenced Nov 23, 2022
@rustbot claim |
matthiaskrgr
added a commit
to matthiaskrgr/rust
that referenced
this issue
Dec 6, 2024
…ondi,workingjubilee Improve documentation for Vec::extend_from_within This closes rust-lang#104762. It rephrases some of the explanations, and greatly improves the clarity of the example. Based on this PR and its discussions: https://github.com/rust-lang/rust/pull/105030/files#r1059808792
rust-timer
added a commit
to rust-lang-ci/rust
that referenced
this issue
Dec 6, 2024
Rollup merge of rust-lang#133790 - HypheX:improve-vec-docs, r=harudagondi,workingjubilee Improve documentation for Vec::extend_from_within This closes rust-lang#104762. It rephrases some of the explanations, and greatly improves the clarity of the example. Based on this PR and its discussions: https://github.com/rust-lang/rust/pull/105030/files#r1059808792
github-actions bot
pushed a commit
to tautschnig/verify-rust-std
that referenced
this issue
Mar 11, 2025
…ondi,workingjubilee Improve documentation for Vec::extend_from_within This closes rust-lang#104762. It rephrases some of the explanations, and greatly improves the clarity of the example. Based on this PR and its discussions: https://github.com/rust-lang/rust/pull/105030/files#r1059808792
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
A-docs
Area: Documentation for any part of the project, including the compiler, standard library, and tools
Location
Vec::extend_from_within
Summary
The examples are confusing because they use increasing integer sequences as both the vector elements and the range. This leas to a confusing example where you call
vec.extend_from_within(2..);
and add2..4
to the end of the vector. When I first read this, I assumed that it was adding the elements of the range to the end of the vector and that the vector had only been initialized with enough "extra room" for three more elements. It took me a while to realize that the range was specifying a range inside the vector and then appending it to the end. Looking back, the nameextend_from_within
should have been a pretty good hint. However, every example adds numbers to the end that matches the first number of the provided range.If you think about the name of the method and the description of the method, you can figure out what this function does. However, the examples can be fairly misleading. I believe this can be rectified by using non-integer values in the vector. For example:
Do others agree that this is an improvement? I know a lot of the other examples use integers, so maybe it's not worth making this example different. At the very least, we could improve it by using different numbers instead 0, 1, 2, etc.
The text was updated successfully, but these errors were encountered: