From 30ba4bd8e2da15ce8e2fe3c8fbc339ee67cb3241 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Sat, 10 Aug 2019 17:16:58 +0000 Subject: [PATCH] Use Result::unwrap_or_else instead of matching --- src/libcore/slice/mod.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/libcore/slice/mod.rs b/src/libcore/slice/mod.rs index 29afc43599620..ce5af13d4ca90 100644 --- a/src/libcore/slice/mod.rs +++ b/src/libcore/slice/mod.rs @@ -1371,10 +1371,7 @@ impl [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]); /// ```