diff options
| author | Lzu Tao <taolzu@gmail.com> | 2019-08-10 17:16:58 +0000 |
|---|---|---|
| committer | Lzu Tao <taolzu@gmail.com> | 2019-08-10 17:16:58 +0000 |
| commit | 30ba4bd8e2da15ce8e2fe3c8fbc339ee67cb3241 (patch) | |
| tree | 38c55f6cbcedbd72e79afe2efecb153361240ff7 /src/libcore/slice | |
| parent | 93839c3fb4e3a3c3341595ac8dc2c7f4e39326d2 (diff) | |
| download | rust-30ba4bd8e2da15ce8e2fe3c8fbc339ee67cb3241.tar.gz rust-30ba4bd8e2da15ce8e2fe3c8fbc339ee67cb3241.zip | |
Use Result::unwrap_or_else instead of matching
Diffstat (limited to 'src/libcore/slice')
| -rw-r--r-- | src/libcore/slice/mod.rs | 5 |
1 files changed, 1 insertions, 4 deletions
diff --git a/src/libcore/slice/mod.rs b/src/libcore/slice/mod.rs index 29afc435996..ce5af13d4ca 100644 --- a/src/libcore/slice/mod.rs +++ b/src/libcore/slice/mod.rs @@ -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]); /// ``` |
