]> git.lizzy.rs Git - rust.git/commitdiff
Add doctests for 's into_values and into_keys methods
authorccQpein <ccqpein@protonmail.com>
Thu, 29 Jul 2021 17:24:25 +0000 (13:24 -0400)
committerccQpein <ccqpein@protonmail.com>
Sun, 22 Aug 2021 13:21:00 +0000 (09:21 -0400)
library/std/src/collections/hash/map.rs

index 933d686521e536c6b331b5ebe3385dbfe3473e96..42e9645a99dc2204c84b683be4b55d658f291dc2 100644 (file)
@@ -971,7 +971,11 @@ pub fn retain<F>(&mut self, f: F)
     /// map.insert("b", 2);
     /// map.insert("c", 3);
     ///
-    /// let vec: Vec<&str> = map.into_keys().collect();
+    /// let mut vec: Vec<&str> = map.into_keys().collect();
+    /// // The `IntoKeys` iterator produces keys in arbitrary order, so the
+    /// // keys must be sorted to test them against a sorted array.
+    /// vec.sort_unstable();
+    /// assert_eq!(vec, ["a", "b", "c"]);
     /// ```
     #[inline]
     #[stable(feature = "map_into_keys_values", since = "1.54.0")]
@@ -993,7 +997,11 @@ pub fn into_keys(self) -> IntoKeys<K, V> {
     /// map.insert("b", 2);
     /// map.insert("c", 3);
     ///
-    /// let vec: Vec<i32> = map.into_values().collect();
+    /// let mut vec: Vec<i32> = map.into_values().collect();
+    /// // The `IntoValues` iterator produces values in arbitrary order, so
+    /// // the values must be sorted to test them against a sorted array.
+    /// vec.sort_unstable();
+    /// assert_eq!(vec, [1, 2, 3]);
     /// ```
     #[inline]
     #[stable(feature = "map_into_keys_values", since = "1.54.0")]