Skip to content

Commit 30ba4bd

Browse files
committed
Use Result::unwrap_or_else instead of matching
1 parent 93839c3 commit 30ba4bd

File tree

1 file changed

+1
-4
lines changed

1 file changed

+1
-4
lines changed

src/libcore/slice/mod.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1371,10 +1371,7 @@ impl<T> [T] {
13711371
/// ```
13721372
/// let mut s = vec![0, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55];
13731373
/// let num = 42;
1374-
/// let idx = match s.binary_search(&num) {
1375-
/// Ok(idx) => idx,
1376-
/// Err(idx) => idx,
1377-
/// };
1374+
/// let idx = s.binary_search(&num).unwrap_or_else(|x| x);
13781375
/// s.insert(idx, num);
13791376
/// assert_eq!(s, [0, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 42, 55]);
13801377
/// ```

0 commit comments

Comments
 (0)