about summary refs log tree commit diff
path: root/src/libcore
diff options
context:
space:
mode:
authorLzu Tao <taolzu@gmail.com>2019-08-10 17:16:58 +0000
committerLzu Tao <taolzu@gmail.com>2019-08-10 17:16:58 +0000
commit30ba4bd8e2da15ce8e2fe3c8fbc339ee67cb3241 (patch)
tree38c55f6cbcedbd72e79afe2efecb153361240ff7 /src/libcore
parent93839c3fb4e3a3c3341595ac8dc2c7f4e39326d2 (diff)
downloadrust-30ba4bd8e2da15ce8e2fe3c8fbc339ee67cb3241.tar.gz
rust-30ba4bd8e2da15ce8e2fe3c8fbc339ee67cb3241.zip
Use Result::unwrap_or_else instead of matching
Diffstat (limited to 'src/libcore')
-rw-r--r--src/libcore/slice/mod.rs5
1 files changed, 1 insertions, 4 deletions
diff --git a/src/libcore/slice/mod.rs b/src/libcore/slice/mod.rs
index 29afc435996..ce5af13d4ca 100644
--- a/src/libcore/slice/mod.rs
+++ b/src/libcore/slice/mod.rs
@@ -1371,10 +1371,7 @@ impl<T> [T] {
     /// ```
     /// let mut s = vec![0, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55];
     /// let num = 42;
-    /// let idx = match s.binary_search(&num) {
-    ///     Ok(idx) => idx,
-    ///     Err(idx) => idx,
-    /// };
+    /// let idx = s.binary_search(&num).unwrap_or_else(|x| x);
     /// s.insert(idx, num);
     /// assert_eq!(s, [0, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 42, 55]);
     /// ```