diff options
| author | Alex Burka <aburka@seas.upenn.edu> | 2016-01-28 11:20:48 -0500 |
|---|---|---|
| committer | Alex Burka <aburka@seas.upenn.edu> | 2016-02-27 02:01:41 -0500 |
| commit | 7eb7c56bd43b2ae12ef8b92e7258d520099a5347 (patch) | |
| tree | 9265a7f93946aa1536e79cb7c42bba9a5e138480 /src/libcollections | |
| parent | b1b4f50678ecd6aaeed9991b860c272be010fc9f (diff) | |
add indexing with RangeInclusive in libcore and libcollections
Diffstat (limited to 'src/libcollections')
| -rw-r--r-- | src/libcollections/lib.rs | 2 | ||||
| -rw-r--r-- | src/libcollections/string.rs | 34 | ||||
| -rw-r--r-- | src/libcollections/vec.rs | 32 |
3 files changed, 66 insertions, 2 deletions
diff --git a/src/libcollections/lib.rs b/src/libcollections/lib.rs index 9c6fdc217dc..2a81e7dcaf7 100644 --- a/src/libcollections/lib.rs +++ b/src/libcollections/lib.rs @@ -40,7 +40,7 @@ #![feature(fmt_internals)] #![feature(fmt_radix)] #![feature(heap_api)] -#![feature(iter_arith)] +#![feature(inclusive_range)] #![feature(iter_arith)] #![feature(lang_items)] #![feature(nonzero)] diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index 62ae7938e15..cae6520bdb2 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -59,7 +59,7 @@ use core::fmt; use core::hash; use core::iter::FromIterator; use core::mem; -use core::ops::{self, Add}; +use core::ops::{self, Add, Index, IndexMut}; use core::ptr; use core::slice; use core::str::pattern::Pattern; @@ -1606,6 +1606,24 @@ impl ops::Index<ops::RangeFull> for String { unsafe { str::from_utf8_unchecked(&self.vec) } } } +#[unstable(feature = "inclusive_range", reason = "recently added, follows RFC", issue = "28237")] +impl ops::Index<ops::RangeInclusive<usize>> for String { + type Output = str; + + #[inline] + fn index(&self, index: ops::RangeInclusive<usize>) -> &str { + Index::index(&**self, index) + } +} +#[unstable(feature = "inclusive_range", reason = "recently added, follows RFC", issue = "28237")] +impl ops::Index<ops::RangeToInclusive<usize>> for String { + type Output = str; + + #[inline] + fn index(&self, index: ops::RangeToInclusive<usize>) -> &str { + Index::index(&**self, index) + } +} #[stable(feature = "derefmut_for_string", since = "1.2.0")] impl ops::IndexMut<ops::Range<usize>> for String { @@ -1635,6 +1653,20 @@ impl ops::IndexMut<ops::RangeFull> for String { unsafe { mem::transmute(&mut *self.vec) } } } +#[unstable(feature = "inclusive_range", reason = "recently added, follows RFC", issue = "28237")] +impl ops::IndexMut<ops::RangeInclusive<usize>> for String { + #[inline] + fn index_mut(&mut self, index: ops::RangeInclusive<usize>) -> &mut str { + IndexMut::index_mut(&mut **self, index) + } +} +#[unstable(feature = "inclusive_range", reason = "recently added, follows RFC", issue = "28237")] +impl ops::IndexMut<ops::RangeToInclusive<usize>> for String { + #[inline] + fn index_mut(&mut self, index: ops::RangeToInclusive<usize>) -> &mut str { + IndexMut::index_mut(&mut **self, index) + } +} #[stable(feature = "rust1", since = "1.0.0")] impl ops::Deref for String { diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index ae442e155c0..841748f3881 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -1225,6 +1225,24 @@ impl<T> ops::Index<ops::RangeFull> for Vec<T> { self } } +#[unstable(feature = "inclusive_range", reason = "recently added, follows RFC", issue = "28237")] +impl<T> ops::Index<ops::RangeInclusive<usize>> for Vec<T> { + type Output = [T]; + + #[inline] + fn index(&self, index: ops::RangeInclusive<usize>) -> &[T] { + Index::index(&**self, index) + } +} +#[unstable(feature = "inclusive_range", reason = "recently added, follows RFC", issue = "28237")] +impl<T> ops::Index<ops::RangeToInclusive<usize>> for Vec<T> { + type Output = [T]; + + #[inline] + fn index(&self, index: ops::RangeToInclusive<usize>) -> &[T] { + Index::index(&**self, index) + } +} #[stable(feature = "rust1", since = "1.0.0")] impl<T> ops::IndexMut<ops::Range<usize>> for Vec<T> { @@ -1254,6 +1272,20 @@ impl<T> ops::IndexMut<ops::RangeFull> for Vec<T> { self } } +#[unstable(feature = "inclusive_range", reason = "recently added, follows RFC", issue = "28237")] +impl<T> ops::IndexMut<ops::RangeInclusive<usize>> for Vec<T> { + #[inline] + fn index_mut(&mut self, index: ops::RangeInclusive<usize>) -> &mut [T] { + IndexMut::index_mut(&mut **self, index) + } +} +#[unstable(feature = "inclusive_range", reason = "recently added, follows RFC", issue = "28237")] +impl<T> ops::IndexMut<ops::RangeToInclusive<usize>> for Vec<T> { + #[inline] + fn index_mut(&mut self, index: ops::RangeToInclusive<usize>) -> &mut [T] { + IndexMut::index_mut(&mut **self, index) + } +} #[stable(feature = "rust1", since = "1.0.0")] impl<T> ops::Deref for Vec<T> { |
