diff options
| author | Steven Fackler <sfackler@gmail.com> | 2014-09-26 21:46:22 -0700 |
|---|---|---|
| committer | Steven Fackler <sfackler@gmail.com> | 2014-09-26 21:48:49 -0700 |
| commit | aa2814fd4e9266ac96b5c95cb44ec7f7ad86703b (patch) | |
| tree | 8631e7e4dc92d47b99cb169b1fb84dae3672c7f3 /src/libcore | |
| parent | d64b4103d688f38c2e9e2daf966d50beeb383f1e (diff) | |
| download | rust-aa2814fd4e9266ac96b5c95cb44ec7f7ad86703b.tar.gz rust-aa2814fd4e9266ac96b5c95cb44ec7f7ad86703b.zip | |
Implement Slice for String and str
Closes #17502
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/str.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/libcore/str.rs b/src/libcore/str.rs index 7e399902a4b..343b8e0b64b 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -1123,6 +1123,7 @@ pub mod traits { use collections::Collection; use iter::Iterator; use option::{Option, Some}; + use ops; use str::{Str, StrSlice, eq_slice}; impl<'a> Ord for &'a str { @@ -1162,6 +1163,28 @@ pub mod traits { #[inline] fn equiv(&self, other: &S) -> bool { eq_slice(*self, other.as_slice()) } } + + impl ops::Slice<uint, str> for str { + #[inline] + fn as_slice_<'a>(&'a self) -> &'a str { + self + } + + #[inline] + fn slice_from_<'a>(&'a self, from: &uint) -> &'a str { + self.slice_from(*from) + } + + #[inline] + fn slice_to_<'a>(&'a self, to: &uint) -> &'a str { + self.slice_to(*to) + } + + #[inline] + fn slice_<'a>(&'a self, from: &uint, to: &uint) -> &'a str { + self.slice(*from, *to) + } + } } /// Any string that can be represented as a slice |
