Skip to content

Better doctests for HashMap's into_values and into_keys methods #87591

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
ChaiTRex opened this issue Jul 29, 2021 · 1 comment · Fixed by #87598
Closed

Better doctests for HashMap's into_values and into_keys methods #87591

ChaiTRex opened this issue Jul 29, 2021 · 1 comment · Fixed by #87598
Labels
A-collections Area: `std::collections` A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools C-enhancement Category: An issue proposing an enhancement or a PR with one. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Comments

@ChaiTRex
Copy link
Contributor

The current doctests for a few methods don't really test anything when they could. The following changes would:

  • improve the documentation for programmers by better showing what the results of the functions are
  • bring the documentation in line with the equivalent methods for BTreeMap, which do include tests like the following
  • act as two free tests of those methods

The current doctest for HashMap's into_keys method can be improved to:

use std::collections::HashMap;

let mut map = HashMap::new();
map.insert("a", 1);
map.insert("b", 2);
map.insert("c", 3);

let mut vec: Vec<&str> = map.into_keys().collect();
vec.sort_unstable();
assert_eq!(vec, ["a", "b", "c"]);

The current doctest for HashMap's into_values method can be improved to:

use std::collections::HashMap;

let mut map = HashMap::new();
map.insert("a", 1);
map.insert("b", 2);
map.insert("c", 3);

let mut vec: Vec<i32> = map.into_values().collect();
vec.sort_unstable();
assert_eq!(vec, [1, 2, 3]);

I would submit a pull request, but my computer is broken. Could someone please make these changes?

@ccqpein
Copy link
Contributor

ccqpein commented Jul 29, 2021

I did it.

@camelid camelid added 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. C-enhancement Category: An issue proposing an enhancement or a PR with one. labels Jul 30, 2021
@bors bors closed this as completed in 1c04856 Aug 23, 2021
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 C-enhancement Category: An issue proposing an enhancement or a PR with one. 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.

3 participants