diff options
| author | Nick Cameron <ncameron@mozilla.com> | 2015-01-04 17:43:24 +1300 |
|---|---|---|
| committer | Nick Cameron <ncameron@mozilla.com> | 2015-01-07 12:02:52 +1300 |
| commit | 0c7f7a5fb8919c6a382f9acd1e921c51f807f625 (patch) | |
| tree | 74a8f54870574e503df68fd62d799552c8664cf8 /src/libcollections | |
| parent | 791f5456859845a4a1814eca45aa900fc62d4e44 (diff) | |
| download | rust-0c7f7a5fb8919c6a382f9acd1e921c51f807f625.tar.gz rust-0c7f7a5fb8919c6a382f9acd1e921c51f807f625.zip | |
fallout
Diffstat (limited to 'src/libcollections')
| -rw-r--r-- | src/libcollections/ring_buf.rs | 2 | ||||
| -rw-r--r-- | src/libcollections/slice.rs | 15 | ||||
| -rw-r--r-- | src/libcollections/str.rs | 14 | ||||
| -rw-r--r-- | src/libcollections/string.rs | 26 | ||||
| -rw-r--r-- | src/libcollections/vec.rs | 49 |
5 files changed, 56 insertions, 50 deletions
diff --git a/src/libcollections/ring_buf.rs b/src/libcollections/ring_buf.rs index eff25b6d385..98e9d6c16b8 100644 --- a/src/libcollections/ring_buf.rs +++ b/src/libcollections/ring_buf.rs @@ -525,7 +525,7 @@ impl<T> RingBuf<T> { /// *num = *num - 2; /// } /// let b: &[_] = &[&mut 3, &mut 1, &mut 2]; - /// assert_eq!(buf.iter_mut().collect::<Vec<&mut int>>()[], b); + /// assert_eq!(&buf.iter_mut().collect::<Vec<&mut int>>()[], b); /// ``` #[stable] pub fn iter_mut<'a>(&'a mut self) -> IterMut<'a, T> { diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs index ca1fed0f78f..e57574fdbce 100644 --- a/src/libcollections/slice.rs +++ b/src/libcollections/slice.rs @@ -1393,15 +1393,20 @@ fn merge_sort<T, F>(v: &mut [T], mut compare: F) where F: FnMut(&T, &T) -> Order #[cfg(test)] mod tests { - use prelude::{Some, None, range, Vec, ToString, Clone, Greater, Less, Equal}; - use prelude::{SliceExt, Iterator, IteratorExt}; - use prelude::AsSlice; - use prelude::{RandomAccessIterator, Ord, SliceConcatExt}; + use core::cmp::Ordering::{Greater, Less, Equal}; + use core::prelude::{Some, None, range, Clone}; + use core::prelude::{Iterator, IteratorExt}; + use core::prelude::{AsSlice}; + use core::prelude::{Ord, FullRange}; use core::default::Default; use core::mem; + use core::ops::Index; + use std::iter::RandomAccessIterator; use std::rand::{Rng, thread_rng}; use std::rc::Rc; - use super::ElementSwaps; + use string::ToString; + use vec::Vec; + use super::{ElementSwaps, SliceConcatExt, SliceExt}; fn square(n: uint) -> uint { n * n } diff --git a/src/libcollections/str.rs b/src/libcollections/str.rs index cb4264ec34f..aacb6d90d6f 100644 --- a/src/libcollections/str.rs +++ b/src/libcollections/str.rs @@ -60,7 +60,7 @@ use core::char::CharExt; use core::clone::Clone; use core::iter::AdditiveIterator; use core::iter::{range, Iterator, IteratorExt}; -use core::ops::{self, llRange, Index}; +use core::ops::{FullRange, Index}; use core::option::Option::{self, Some, None}; use core::slice::AsSlice; use core::str as core_str; @@ -408,7 +408,7 @@ Section: Trait implementations /// Any string that can be represented as a slice. #[stable] -pub trait StrExt: Index<FullRange, str> { +pub trait StrExt: Index<FullRange, Output = str> { /// Escapes each char in `s` with `char::escape_default`. #[unstable = "return type may change to be an iterator"] fn escape_default(&self) -> String { @@ -1339,12 +1339,6 @@ pub trait StrExt: Index<FullRange, str> { fn trim_left(&self) -> &str { UnicodeStr::trim_left(self.index(&FullRange)) } - - /// Returns a string with trailing whitespace removed. - #[stable] - fn trim_right(&self) -> &str { - UnicodeStr::trim_right(self.index(&FullRange)) - } } #[stable] @@ -2133,7 +2127,7 @@ mod tests { let mut bytes = [0u8; 4]; for c in range(0u32, 0x110000).filter_map(|c| ::core::char::from_u32(c)) { let len = c.encode_utf8(&mut bytes).unwrap_or(0); - let s = ::core::str::from_utf8(bytes.index(&(0..len))).unwrap(); + let s = ::core::str::from_utf8(&bytes[..len]).unwrap(); if Some(c) != s.chars().next() { panic!("character {:x}={} does not decode correctly", c as u32, c); } @@ -2145,7 +2139,7 @@ mod tests { let mut bytes = [0u8; 4]; for c in range(0u32, 0x110000).filter_map(|c| ::core::char::from_u32(c)) { let len = c.encode_utf8(&mut bytes).unwrap_or(0); - let s = ::core::str::from_utf8(bytes.index(&(0..len))).unwrap(); + let s = ::core::str::from_utf8(&bytes[..len]).unwrap(); if Some(c) != s.chars().rev().next() { panic!("character {:x}={} does not decode correctly", c as u32, c); } diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index 69ff513a85b..20bc08416dc 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -22,7 +22,7 @@ use core::fmt; use core::hash; use core::iter::FromIterator; use core::mem; -use core::ops::{self, Deref, Add}; +use core::ops::{self, Deref, Add, Index}; use core::ptr; use core::raw::Slice as RawSlice; use unicode::str as unicode_str; @@ -818,28 +818,29 @@ impl<'a> Add<&'a str> for String { } } -impl ops::Index<ops::Range<uint>, str> for String { +impl ops::Index<ops::Range<uint>> for String { + type Output = str; #[inline] fn index(&self, index: &ops::Range<uint>) -> &str { &self.index(&FullRange)[*index] } } - -impl ops::Index<ops::RangeTo<uint>, str> for String { +impl ops::Index<ops::RangeTo<uint>> for String { + type Output = str; #[inline] fn index(&self, index: &ops::RangeTo<uint>) -> &str { &self.index(&FullRange)[*index] } } - -impl ops::Index<ops::RangeFrom<uint>, str> for String { +impl ops::Index<ops::RangeFrom<uint>> for String { + type Output = str; #[inline] fn index(&self, index: &ops::RangeFrom<uint>) -> &str { &self.index(&FullRange)[*index] } } - -impl ops::Index<ops::FullRange, str> for String { +impl ops::Index<ops::FullRange> for String { + type Output = str; #[inline] fn index(&self, _index: &ops::FullRange) -> &str { unsafe { mem::transmute(self.vec.as_slice()) } @@ -949,6 +950,7 @@ mod tests { use str::Utf8Error; use core::iter::repeat; use super::{as_string, CowString}; + use core::ops::FullRange; #[test] fn test_as_string() { @@ -1230,10 +1232,10 @@ mod tests { #[test] fn test_slicing() { let s = "foobar".to_string(); - assert_eq!("foobar", s.index(&FullRange)); - assert_eq!("foo", s.index(&(0..3))); - assert_eq!("bar", s.index(&(3..))); - assert_eq!("oob", s.index(&(1..4))); + assert_eq!("foobar", &s[]); + assert_eq!("foo", &s[..3]); + assert_eq!("bar", &s[3..]); + assert_eq!("oob", &s[1..4]); } #[test] diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index 3f667698bae..1cfbbdf6cb8 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -1209,62 +1209,66 @@ impl<T> IndexMut<uint> for Vec<T> { } } -impl<T> ops::Index<ops::Range<uint>, [T]> for Vec<T> { + +impl<T> ops::Index<ops::Range<uint>> for Vec<T> { + type Output = [T]; #[inline] fn index(&self, index: &ops::Range<uint>) -> &[T] { self.as_slice().index(index) } } - -impl<T> ops::Index<ops::RangeTo<uint>, [T]> for Vec<T> { +impl<T> ops::Index<ops::RangeTo<uint>> for Vec<T> { + type Output = [T]; #[inline] fn index(&self, index: &ops::RangeTo<uint>) -> &[T] { self.as_slice().index(index) } } - -impl<T> ops::Index<ops::RangeFrom<uint>, [T]> for Vec<T> { +impl<T> ops::Index<ops::RangeFrom<uint>> for Vec<T> { + type Output = [T]; #[inline] fn index(&self, index: &ops::RangeFrom<uint>) -> &[T] { self.as_slice().index(index) } } - -impl<T> ops::Index<ops::FullRange, [T]> for Vec<T> { +impl<T> ops::Index<ops::FullRange> for Vec<T> { + type Output = [T]; #[inline] fn index(&self, _index: &ops::FullRange) -> &[T] { self.as_slice() } } -impl<T> ops::IndexMut<ops::Range<uint>, [T]> for Vec<T> { +impl<T> ops::IndexMut<ops::Range<uint>> for Vec<T> { + type Output = [T]; #[inline] fn index_mut(&mut self, index: &ops::Range<uint>) -> &mut [T] { self.as_mut_slice().index_mut(index) } } - -impl<T> ops::IndexMut<ops::RangeTo<uint>, [T]> for Vec<T> { +impl<T> ops::IndexMut<ops::RangeTo<uint>> for Vec<T> { + type Output = [T]; #[inline] fn index_mut(&mut self, index: &ops::RangeTo<uint>) -> &mut [T] { self.as_mut_slice().index_mut(index) } } - -impl<T> ops::IndexMut<ops::RangeFrom<uint>, [T]> for Vec<T> { +impl<T> ops::IndexMut<ops::RangeFrom<uint>> for Vec<T> { + type Output = [T]; #[inline] fn index_mut(&mut self, index: &ops::RangeFrom<uint>) -> &mut [T] { self.as_mut_slice().index_mut(index) } } - -impl<T> ops::IndexMut<ops::FullRange, [T]> for Vec<T> { +impl<T> ops::IndexMut<ops::FullRange> for Vec<T> { + type Output = [T]; #[inline] fn index_mut(&mut self, _index: &ops::FullRange) -> &mut [T] { self.as_mut_slice() } } + #[stable] impl<T> ops::Deref for Vec<T> { type Target = [T]; @@ -1795,6 +1799,7 @@ mod tests { use prelude::*; use core::mem::size_of; use core::iter::repeat; + use core::ops::FullRange; use test::Bencher; use super::as_vec; @@ -1932,7 +1937,7 @@ mod tests { let (left, right) = values.split_at_mut(2); { let left: &[_] = left; - assert!(left[0..left.len()] == [1, 2][]); + assert!(&left[..left.len()] == &[1, 2][]); } for p in left.iter_mut() { *p += 1; @@ -1940,7 +1945,7 @@ mod tests { { let right: &[_] = right; - assert!(right[0..right.len()] == [3, 4, 5][]); + assert!(&right[..right.len()] == &[3, 4, 5][]); } for p in right.iter_mut() { *p += 2; @@ -2111,35 +2116,35 @@ mod tests { #[should_fail] fn test_slice_out_of_bounds_1() { let x: Vec<int> = vec![1, 2, 3, 4, 5]; - x[-1..]; + &x[(-1)..]; } #[test] #[should_fail] fn test_slice_out_of_bounds_2() { let x: Vec<int> = vec![1, 2, 3, 4, 5]; - x.index(&(0..6)); + &x[..6]; } #[test] #[should_fail] fn test_slice_out_of_bounds_3() { let x: Vec<int> = vec![1, 2, 3, 4, 5]; - x[-1..4]; + &x[(-1)..4]; } #[test] #[should_fail] fn test_slice_out_of_bounds_4() { let x: Vec<int> = vec![1, 2, 3, 4, 5]; - x.index(&(1..6)); + &x[1..6]; } #[test] #[should_fail] fn test_slice_out_of_bounds_5() { let x: Vec<int> = vec![1, 2, 3, 4, 5]; - x.index(&(3..2)); + &x[3..2]; } #[test] @@ -2385,7 +2390,7 @@ mod tests { b.bytes = src_len as u64; b.iter(|| { - let dst = src.clone().as_slice().to_vec(); + let dst = src.clone()[].to_vec(); assert_eq!(dst.len(), src_len); assert!(dst.iter().enumerate().all(|(i, x)| i == *x)); }); |
