Use Result::unwrap_or_else instead of matching
This commit is contained in:
parent
93839c3fb4
commit
30ba4bd8e2
1 changed files with 1 additions and 4 deletions
|
|
@ -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]);
|
||||
/// ```
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue