Closed
Description
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?