Skip to content

VecDeque documentation for as_slices misleads newbies. #141217

Closed
@VorfeedCanal

Description

@VorfeedCanal

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.

Metadata

Metadata

Assignees

Labels

A-collectionsArea: `std::collections`A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsT-libsRelevant to the library team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions