Use Result::unwrap_or_else instead of matching

This commit is contained in:
Lzu Tao
2019-08-10 17:16:58 +00:00
parent 93839c3fb4
commit 30ba4bd8e2
+1 -4
View File
@@ -1371,10 +1371,7 @@ pub fn ends_with(&self, needle: &[T]) -> bool
/// ```
/// 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]);
/// ```