Skip to content

VecDeque documentation for as_slices misleads newbies. #141217

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

Closed
VorfeedCanal opened this issue May 18, 2025 · 1 comment · Fixed by #141230
Closed

VecDeque documentation for as_slices misleads newbies. #141217

VorfeedCanal opened this issue May 18, 2025 · 1 comment · Fixed by #141230
Assignees
Labels
A-collections Area: `std::collections` A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools T-libs Relevant to the library team, which will review and decide on the PR/issue.

Comments

@VorfeedCanal
Copy link

VorfeedCanal commented May 18, 2025

Location

https://doc.rust-lang.org/std/collections/struct.VecDeque.html#method.as_slices

Summary

VecDeque documentation for as_slices method includes misleading test. It does few push'es and the asserts a particular shape of deque via assert_eq!.

This may mislead people and make them believe there are some guarantees about what particular slices are used for a given deque.

Instead we should add a line that says that particular split of elements between slices is not guaranteed and replace example with something like this:

let mut deque = VecDeque::new();

deque.push_back(0);
deque.push_back(1);
deque.push_back(2);

let slices = deque.as_slices();
assert!(slices.0.iter().chain(slices.1.iter()).eq([0, 1, 2].iter()));

deque.push_front(10);
deque.push_front(9);

let slices = deque.as_slices();
assert!(slices.0.iter().chain(slices.1.iter()).eq([9, 10, 0, 1, 2].iter()));

That way is would be clear that while content of two returned slices is guaranteed – but particular shape of split between them is not guaranteed.

@VorfeedCanal VorfeedCanal added the A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools label May 18, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label May 18, 2025
@xizheyin
Copy link
Contributor

@rustbot claim

@fmease fmease added A-collections Area: `std::collections` T-libs Relevant to the library team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels May 18, 2025
@bors bors closed this as completed in b5edec2 May 22, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue May 22, 2025
Rollup merge of rust-lang#141230 - xizheyin:issue-141217, r=tgross35

std: fix doctest and explain for `as_slices` and `as_mut_slices` in `VecDeque`

Fixes rust-lang#141217

r? libs
github-actions bot pushed a commit to model-checking/verify-rust-std that referenced this issue May 26, 2025
std: fix doctest and explain for `as_slices` and `as_mut_slices` in `VecDeque`

Fixes rust-lang#141217

r? libs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-collections Area: `std::collections` A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants