diff options
| author | djzin <noreply@github.com> | 2016-12-23 19:15:56 +0000 |
|---|---|---|
| committer | djzin <noreply@github.com> | 2017-01-14 16:51:50 +0000 |
| commit | 35f23e8211147372f1e8917f7b41593a1aec9865 (patch) | |
| tree | 87c5f9b99a705a6ccd648ea6553d6a75176ab970 /src/libcollections/string.rs | |
| parent | ef04fc82b198487b0ffb1832304714519f9f1a35 (diff) | |
| download | rust-35f23e8211147372f1e8917f7b41593a1aec9865.tar.gz rust-35f23e8211147372f1e8917f7b41593a1aec9865.zip | |
have RangeArgument return a Bound<&T> from each of its methods
Diffstat (limited to 'src/libcollections/string.rs')
| -rw-r--r-- | src/libcollections/string.rs | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index 157c762b4a7..5210c25b4e5 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -68,6 +68,7 @@ use std_unicode::str as unicode_str; use borrow::{Cow, ToOwned}; use range::RangeArgument; +use Bound::{Excluded, Included, Unbounded}; use str::{self, FromStr, Utf8Error, Chars}; use vec::Vec; use boxed::Box; @@ -1350,8 +1351,16 @@ impl String { // Because the range removal happens in Drop, if the Drain iterator is leaked, // the removal will not happen. let len = self.len(); - let start = *range.start().unwrap_or(&0); - let end = *range.end().unwrap_or(&len); + let start = match range.start() { + Included(&n) => n, + Excluded(&n) => n + 1, + Unbounded => 0, + }; + let end = match range.end() { + Included(&n) => n + 1, + Excluded(&n) => n, + Unbounded => len, + }; // Take out two simultaneous borrows. The &mut String won't be accessed // until iteration is over, in Drop. |
