mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-17 15:33:25 +03:00
Use Result::unwrap_or_else instead of matching
This commit is contained in:
@@ -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]);
|
||||
/// ```
|
||||
|
||||
Reference in New Issue
Block a user