Skip to content

Commit

Permalink
Use Result::unwrap_or_else instead of matching
Browse files Browse the repository at this point in the history
  • Loading branch information
tesuji committed Aug 10, 2019
1 parent 93839c3 commit 30ba4bd
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions src/libcore/slice/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
/// ```
Expand Down

0 comments on commit 30ba4bd

Please sign in to comment.