]> git.lizzy.rs Git - rust.git/commitdiff
libcollections: remove unnecessary `as_slice()` calls
authorJorge Aparicio <japaricious@gmail.com>
Thu, 27 Nov 2014 16:45:50 +0000 (11:45 -0500)
committerJorge Aparicio <japaricious@gmail.com>
Sun, 7 Dec 2014 00:05:58 +0000 (19:05 -0500)
src/libcollections/binary_heap.rs
src/libcollections/bit.rs
src/libcollections/btree/node.rs
src/libcollections/dlist.rs
src/libcollections/enum_set.rs
src/libcollections/ring_buf.rs
src/libcollections/slice.rs
src/libcollections/str.rs
src/libcollections/string.rs
src/libcollections/vec.rs
src/libcollections/vec_map.rs

index 330b93929746c037c7a6c591450765c3fd1dab78..53d20aab24d61bece6430de05071e24c1b1ce53d 100644 (file)
@@ -769,8 +769,8 @@ fn check_to_vec(mut data: Vec<int>) {
         v.sort();
         data.sort();
 
-        assert_eq!(v.as_slice(), data.as_slice());
-        assert_eq!(heap.into_sorted_vec().as_slice(), data.as_slice());
+        assert_eq!(v, data);
+        assert_eq!(heap.into_sorted_vec(), data);
     }
 
     #[test]
@@ -812,7 +812,7 @@ fn test_empty_replace() {
     fn test_from_iter() {
         let xs = vec!(9u, 8, 7, 6, 5, 4, 3, 2, 1);
 
-        let mut q: BinaryHeap<uint> = xs.as_slice().iter().rev().map(|&x| x).collect();
+        let mut q: BinaryHeap<uint> = xs.iter().rev().map(|&x| x).collect();
 
         for &x in xs.iter() {
             assert_eq!(q.pop().unwrap(), x);
index 903a9bd982324dcae57494bdb36a438149fdc2f1..953e432fd4a75029e5cf5ac7589a3dced54d0be2 100644 (file)
@@ -1692,10 +1692,10 @@ mod tests {
     #[test]
     fn test_to_str() {
         let zerolen = Bitv::new();
-        assert_eq!(zerolen.to_string().as_slice(), "");
+        assert_eq!(zerolen.to_string(), "");
 
         let eightbits = Bitv::with_capacity(8u, false);
-        assert_eq!(eightbits.to_string().as_slice(), "00000000")
+        assert_eq!(eightbits.to_string(), "00000000")
     }
 
     #[test]
@@ -1718,7 +1718,7 @@ fn test_2_elements() {
         let mut b = bitv::Bitv::with_capacity(2, false);
         b.set(0, true);
         b.set(1, false);
-        assert_eq!(b.to_string().as_slice(), "10");
+        assert_eq!(b.to_string(), "10");
     }
 
     #[test]
@@ -2029,7 +2029,7 @@ fn test_equal_sneaky_big() {
     fn test_from_bytes() {
         let bitv = from_bytes(&[0b10110110, 0b00000000, 0b11111111]);
         let str = format!("{}{}{}", "10110110", "00000000", "11111111");
-        assert_eq!(bitv.to_string().as_slice(), str.as_slice());
+        assert_eq!(bitv.to_string(), str);
     }
 
     #[test]
@@ -2048,7 +2048,7 @@ fn test_to_bytes() {
     fn test_from_bools() {
         let bools = vec![true, false, true, true];
         let bitv: Bitv = bools.iter().map(|n| *n).collect();
-        assert_eq!(bitv.to_string().as_slice(), "1011");
+        assert_eq!(bitv.to_string(), "1011");
     }
 
     #[test]
@@ -2207,7 +2207,7 @@ fn test_bitv_set_intersection() {
 
         let expected = [3, 5, 11, 77];
         let actual = a.intersection(&b).collect::<Vec<uint>>();
-        assert_eq!(actual.as_slice(), expected.as_slice());
+        assert_eq!(actual, expected);
     }
 
     #[test]
@@ -2226,7 +2226,7 @@ fn test_bitv_set_difference() {
 
         let expected = [1, 5, 500];
         let actual = a.difference(&b).collect::<Vec<uint>>();
-        assert_eq!(actual.as_slice(), expected.as_slice());
+        assert_eq!(actual, expected);
     }
 
     #[test]
@@ -2247,7 +2247,7 @@ fn test_bitv_set_symmetric_difference() {
 
         let expected = [1, 5, 11, 14, 220];
         let actual = a.symmetric_difference(&b).collect::<Vec<uint>>();
-        assert_eq!(actual.as_slice(), expected.as_slice());
+        assert_eq!(actual, expected);
     }
 
     #[test]
@@ -2272,7 +2272,7 @@ fn test_bitv_set_union() {
 
         let expected = [1, 3, 5, 9, 11, 13, 19, 24, 160, 200];
         let actual = a.union(&b).collect::<Vec<uint>>();
-        assert_eq!(actual.as_slice(), expected.as_slice());
+        assert_eq!(actual, expected);
     }
 
     #[test]
index b40ff35cca1c62707a69374a76ea79f95d0bdc2c..2c681b6b1d354a44967c74ee4335885817e15389 100644 (file)
@@ -169,22 +169,22 @@ pub unsafe fn unsafe_key_mut(&mut self, index: uint) -> &mut K {
 
     /// Get the node's value at the given index
     pub fn val(&self, index: uint) -> Option<&V> {
-        self.vals.as_slice().get(index)
+        self.vals.get(index)
     }
 
     /// Get the node's value at the given index
     pub fn val_mut(&mut self, index: uint) -> Option<&mut V> {
-        self.vals.as_mut_slice().get_mut(index)
+        self.vals.get_mut(index)
     }
 
     /// Get the node's value mutably without any bounds checks.
     pub unsafe fn unsafe_val_mut(&mut self, index: uint) -> &mut V {
-        self.vals.as_mut_slice().unsafe_mut(index)
+        self.vals.unsafe_mut(index)
     }
 
     /// Get the node's edge at the given index
     pub fn edge(&self, index: uint) -> Option<&Node<K,V>> {
-        self.edges.as_slice().get(index)
+        self.edges.get(index)
     }
 
     /// Get the node's edge mutably at the given index
@@ -281,8 +281,8 @@ pub fn handle_underflow(&mut self, underflowed_child_index: uint) {
     pub fn iter<'a>(&'a self) -> Traversal<'a, K, V> {
         let is_leaf = self.is_leaf();
         Traversal {
-            elems: self.keys.as_slice().iter().zip(self.vals.as_slice().iter()),
-            edges: self.edges.as_slice().iter(),
+            elems: self.keys.iter().zip(self.vals.iter()),
+            edges: self.edges.iter(),
             head_is_edge: true,
             tail_is_edge: true,
             has_edges: !is_leaf,
@@ -292,7 +292,7 @@ pub fn iter<'a>(&'a self) -> Traversal<'a, K, V> {
     pub fn iter_mut<'a>(&'a mut self) -> MutTraversal<'a, K, V> {
         let is_leaf = self.is_leaf();
         MutTraversal {
-            elems: self.keys.as_slice().iter().zip(self.vals.as_mut_slice().iter_mut()),
+            elems: self.keys.iter().zip(self.vals.as_mut_slice().iter_mut()),
             edges: self.edges.as_mut_slice().iter_mut(),
             head_is_edge: true,
             tail_is_edge: true,
@@ -477,7 +477,7 @@ fn split<T>(left: &mut Vec<T>) -> Vec<T> {
     let left_len = len - right_len;
     let mut right = Vec::with_capacity(left.capacity());
     unsafe {
-        let left_ptr = left.as_slice().unsafe_get(left_len) as *const _;
+        let left_ptr = left.unsafe_get(left_len) as *const _;
         let right_ptr = right.as_mut_slice().as_mut_ptr();
         ptr::copy_nonoverlapping_memory(right_ptr, left_ptr, right_len);
         left.set_len(left_len);
index 39cdf0c456413d48f81393993d3168591c525e64..a30bb9e978b508c6644acd6826bf63c1b8c66058 100644 (file)
@@ -926,7 +926,7 @@ fn test_prepend() {
         let mut m = list_from(v.as_slice());
         m.prepend(list_from(u.as_slice()));
         check_links(&m);
-        u.extend(v.as_slice().iter().map(|&b| b));
+        u.extend(v.iter().map(|&b| b));
         assert_eq!(u.len(), m.len());
         for elt in u.into_iter() {
             assert_eq!(m.pop_front(), Some(elt))
@@ -1133,7 +1133,7 @@ fn test_send() {
         spawn(proc() {
             check_links(&n);
             let a: &[_] = &[&1,&2,&3];
-            assert_eq!(a, n.iter().collect::<Vec<&int>>().as_slice());
+            assert_eq!(a, n.iter().collect::<Vec<&int>>());
         });
     }
 
@@ -1224,12 +1224,12 @@ fn test_fuzz() {
     #[test]
     fn test_show() {
         let list: DList<int> = range(0i, 10).collect();
-        assert!(list.to_string().as_slice() == "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]");
+        assert!(list.to_string() == "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]");
 
         let list: DList<&str> = vec!["just", "one", "test", "more"].iter()
                                                                    .map(|&s| s)
                                                                    .collect();
-        assert!(list.to_string().as_slice() == "[just, one, test, more]");
+        assert!(list.to_string() == "[just, one, test, more]");
     }
 
     #[cfg(test)]
index 2cbde0168a2e80444c13641f2557a26e0cc7842d..5e77cf66726a872c557409b81b2374c850a55cab 100644 (file)
@@ -288,11 +288,11 @@ fn test_new() {
     #[test]
     fn test_show() {
         let mut e = EnumSet::new();
-        assert_eq!("{}", e.to_string().as_slice());
+        assert_eq!("{}", e.to_string());
         e.insert(A);
-        assert_eq!("{A}", e.to_string().as_slice());
+        assert_eq!("{A}", e.to_string());
         e.insert(C);
-        assert_eq!("{A, C}", e.to_string().as_slice());
+        assert_eq!("{A, C}", e.to_string());
     }
 
     #[test]
index e11ba35367e2eb56770887eb8e3ea9cdb9f18af6..d9e5dde96ceee7693be941db311b068b517dc98b 100644 (file)
@@ -1246,7 +1246,7 @@ fn test_iter() {
         }
         {
             let b: &[_] = &[&0,&1,&2,&3,&4];
-            assert_eq!(d.iter().collect::<Vec<&int>>().as_slice(), b);
+            assert_eq!(d.iter().collect::<Vec<&int>>(), b);
         }
 
         for i in range(6i, 9) {
@@ -1254,7 +1254,7 @@ fn test_iter() {
         }
         {
             let b: &[_] = &[&8,&7,&6,&0,&1,&2,&3,&4];
-            assert_eq!(d.iter().collect::<Vec<&int>>().as_slice(), b);
+            assert_eq!(d.iter().collect::<Vec<&int>>(), b);
         }
 
         let mut it = d.iter();
@@ -1277,14 +1277,14 @@ fn test_rev_iter() {
         }
         {
             let b: &[_] = &[&4,&3,&2,&1,&0];
-            assert_eq!(d.iter().rev().collect::<Vec<&int>>().as_slice(), b);
+            assert_eq!(d.iter().rev().collect::<Vec<&int>>(), b);
         }
 
         for i in range(6i, 9) {
             d.push_front(i);
         }
         let b: &[_] = &[&4,&3,&2,&1,&0,&6,&7,&8];
-        assert_eq!(d.iter().rev().collect::<Vec<&int>>().as_slice(), b);
+        assert_eq!(d.iter().rev().collect::<Vec<&int>>(), b);
     }
 
     #[test]
@@ -1495,12 +1495,12 @@ fn test_ord() {
     #[test]
     fn test_show() {
         let ringbuf: RingBuf<int> = range(0i, 10).collect();
-        assert!(format!("{}", ringbuf).as_slice() == "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]");
+        assert!(format!("{}", ringbuf) == "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]");
 
         let ringbuf: RingBuf<&str> = vec!["just", "one", "test", "more"].iter()
                                                                         .map(|&s| s)
                                                                         .collect();
-        assert!(format!("{}", ringbuf).as_slice() == "[just, one, test, more]");
+        assert!(format!("{}", ringbuf) == "[just, one, test, more]");
     }
 
     #[test]
index 6c13abdaf892f52fd2460fdcf57c94dd93b096d5..57e16fd7454ff218e8097d119ef07d0c3099217a 100644 (file)
@@ -1652,24 +1652,24 @@ fn test_splitator() {
         let xs = &[1i,2,3,4,5];
 
         let splits: &[&[int]] = &[&[1], &[3], &[5]];
-        assert_eq!(xs.split(|x| *x % 2 == 0).collect::<Vec<&[int]>>().as_slice(),
+        assert_eq!(xs.split(|x| *x % 2 == 0).collect::<Vec<&[int]>>(),
                    splits);
         let splits: &[&[int]] = &[&[], &[2,3,4,5]];
-        assert_eq!(xs.split(|x| *x == 1).collect::<Vec<&[int]>>().as_slice(),
+        assert_eq!(xs.split(|x| *x == 1).collect::<Vec<&[int]>>(),
                    splits);
         let splits: &[&[int]] = &[&[1,2,3,4], &[]];
-        assert_eq!(xs.split(|x| *x == 5).collect::<Vec<&[int]>>().as_slice(),
+        assert_eq!(xs.split(|x| *x == 5).collect::<Vec<&[int]>>(),
                    splits);
         let splits: &[&[int]] = &[&[1,2,3,4,5]];
-        assert_eq!(xs.split(|x| *x == 10).collect::<Vec<&[int]>>().as_slice(),
+        assert_eq!(xs.split(|x| *x == 10).collect::<Vec<&[int]>>(),
                    splits);
         let splits: &[&[int]] = &[&[], &[], &[], &[], &[], &[]];
-        assert_eq!(xs.split(|_| true).collect::<Vec<&[int]>>().as_slice(),
+        assert_eq!(xs.split(|_| true).collect::<Vec<&[int]>>(),
                    splits);
 
         let xs: &[int] = &[];
         let splits: &[&[int]] = &[&[]];
-        assert_eq!(xs.split(|x| *x == 5).collect::<Vec<&[int]>>().as_slice(), splits);
+        assert_eq!(xs.split(|x| *x == 5).collect::<Vec<&[int]>>(), splits);
     }
 
     #[test]
@@ -1677,18 +1677,18 @@ fn test_splitnator() {
         let xs = &[1i,2,3,4,5];
 
         let splits: &[&[int]] = &[&[1,2,3,4,5]];
-        assert_eq!(xs.splitn(0, |x| *x % 2 == 0).collect::<Vec<&[int]>>().as_slice(),
+        assert_eq!(xs.splitn(0, |x| *x % 2 == 0).collect::<Vec<&[int]>>(),
                    splits);
         let splits: &[&[int]] = &[&[1], &[3,4,5]];
-        assert_eq!(xs.splitn(1, |x| *x % 2 == 0).collect::<Vec<&[int]>>().as_slice(),
+        assert_eq!(xs.splitn(1, |x| *x % 2 == 0).collect::<Vec<&[int]>>(),
                    splits);
         let splits: &[&[int]] = &[&[], &[], &[], &[4,5]];
-        assert_eq!(xs.splitn(3, |_| true).collect::<Vec<&[int]>>().as_slice(),
+        assert_eq!(xs.splitn(3, |_| true).collect::<Vec<&[int]>>(),
                    splits);
 
         let xs: &[int] = &[];
         let splits: &[&[int]] = &[&[]];
-        assert_eq!(xs.splitn(1, |x| *x == 5).collect::<Vec<&[int]>>().as_slice(), splits);
+        assert_eq!(xs.splitn(1, |x| *x == 5).collect::<Vec<&[int]>>(), splits);
     }
 
     #[test]
@@ -1696,18 +1696,18 @@ fn test_splitnator_mut() {
         let xs = &mut [1i,2,3,4,5];
 
         let splits: &[&mut [int]] = &[&mut [1,2,3,4,5]];
-        assert_eq!(xs.splitn_mut(0, |x| *x % 2 == 0).collect::<Vec<&mut [int]>>().as_slice(),
+        assert_eq!(xs.splitn_mut(0, |x| *x % 2 == 0).collect::<Vec<&mut [int]>>(),
                    splits);
         let splits: &[&mut [int]] = &[&mut [1], &mut [3,4,5]];
-        assert_eq!(xs.splitn_mut(1, |x| *x % 2 == 0).collect::<Vec<&mut [int]>>().as_slice(),
+        assert_eq!(xs.splitn_mut(1, |x| *x % 2 == 0).collect::<Vec<&mut [int]>>(),
                    splits);
         let splits: &[&mut [int]] = &[&mut [], &mut [], &mut [], &mut [4,5]];
-        assert_eq!(xs.splitn_mut(3, |_| true).collect::<Vec<&mut [int]>>().as_slice(),
+        assert_eq!(xs.splitn_mut(3, |_| true).collect::<Vec<&mut [int]>>(),
                    splits);
 
         let xs: &mut [int] = &mut [];
         let splits: &[&mut [int]] = &[&mut []];
-        assert_eq!(xs.splitn_mut(1, |x| *x == 5).collect::<Vec<&mut [int]>>().as_slice(),
+        assert_eq!(xs.splitn_mut(1, |x| *x == 5).collect::<Vec<&mut [int]>>(),
                    splits);
     }
 
@@ -1716,21 +1716,21 @@ fn test_rsplitator() {
         let xs = &[1i,2,3,4,5];
 
         let splits: &[&[int]] = &[&[5], &[3], &[1]];
-        assert_eq!(xs.split(|x| *x % 2 == 0).rev().collect::<Vec<&[int]>>().as_slice(),
+        assert_eq!(xs.split(|x| *x % 2 == 0).rev().collect::<Vec<&[int]>>(),
                    splits);
         let splits: &[&[int]] = &[&[2,3,4,5], &[]];
-        assert_eq!(xs.split(|x| *x == 1).rev().collect::<Vec<&[int]>>().as_slice(),
+        assert_eq!(xs.split(|x| *x == 1).rev().collect::<Vec<&[int]>>(),
                    splits);
         let splits: &[&[int]] = &[&[], &[1,2,3,4]];
-        assert_eq!(xs.split(|x| *x == 5).rev().collect::<Vec<&[int]>>().as_slice(),
+        assert_eq!(xs.split(|x| *x == 5).rev().collect::<Vec<&[int]>>(),
                    splits);
         let splits: &[&[int]] = &[&[1,2,3,4,5]];
-        assert_eq!(xs.split(|x| *x == 10).rev().collect::<Vec<&[int]>>().as_slice(),
+        assert_eq!(xs.split(|x| *x == 10).rev().collect::<Vec<&[int]>>(),
                    splits);
 
         let xs: &[int] = &[];
         let splits: &[&[int]] = &[&[]];
-        assert_eq!(xs.split(|x| *x == 5).rev().collect::<Vec<&[int]>>().as_slice(), splits);
+        assert_eq!(xs.split(|x| *x == 5).rev().collect::<Vec<&[int]>>(), splits);
     }
 
     #[test]
@@ -1738,18 +1738,18 @@ fn test_rsplitnator() {
         let xs = &[1,2,3,4,5];
 
         let splits: &[&[int]] = &[&[1,2,3,4,5]];
-        assert_eq!(xs.rsplitn(0, |x| *x % 2 == 0).collect::<Vec<&[int]>>().as_slice(),
+        assert_eq!(xs.rsplitn(0, |x| *x % 2 == 0).collect::<Vec<&[int]>>(),
                    splits);
         let splits: &[&[int]] = &[&[5], &[1,2,3]];
-        assert_eq!(xs.rsplitn(1, |x| *x % 2 == 0).collect::<Vec<&[int]>>().as_slice(),
+        assert_eq!(xs.rsplitn(1, |x| *x % 2 == 0).collect::<Vec<&[int]>>(),
                    splits);
         let splits: &[&[int]] = &[&[], &[], &[], &[1,2]];
-        assert_eq!(xs.rsplitn(3, |_| true).collect::<Vec<&[int]>>().as_slice(),
+        assert_eq!(xs.rsplitn(3, |_| true).collect::<Vec<&[int]>>(),
                    splits);
 
         let xs: &[int] = &[];
         let splits: &[&[int]] = &[&[]];
-        assert_eq!(xs.rsplitn(1, |x| *x == 5).collect::<Vec<&[int]>>().as_slice(), splits);
+        assert_eq!(xs.rsplitn(1, |x| *x == 5).collect::<Vec<&[int]>>(), splits);
     }
 
     #[test]
@@ -1757,9 +1757,9 @@ fn test_windowsator() {
         let v = &[1i,2,3,4];
 
         let wins: &[&[int]] = &[&[1,2], &[2,3], &[3,4]];
-        assert_eq!(v.windows(2).collect::<Vec<&[int]>>().as_slice(), wins);
+        assert_eq!(v.windows(2).collect::<Vec<&[int]>>(), wins);
         let wins: &[&[int]] = &[&[1i,2,3], &[2,3,4]];
-        assert_eq!(v.windows(3).collect::<Vec<&[int]>>().as_slice(), wins);
+        assert_eq!(v.windows(3).collect::<Vec<&[int]>>(), wins);
         assert!(v.windows(6).next().is_none());
     }
 
@@ -1775,14 +1775,14 @@ fn test_chunksator() {
         let v = &[1i,2,3,4,5];
 
         let chunks: &[&[int]] = &[&[1i,2], &[3,4], &[5]];
-        assert_eq!(v.chunks(2).collect::<Vec<&[int]>>().as_slice(), chunks);
+        assert_eq!(v.chunks(2).collect::<Vec<&[int]>>(), chunks);
         let chunks: &[&[int]] = &[&[1i,2,3], &[4,5]];
-        assert_eq!(v.chunks(3).collect::<Vec<&[int]>>().as_slice(), chunks);
+        assert_eq!(v.chunks(3).collect::<Vec<&[int]>>(), chunks);
         let chunks: &[&[int]] = &[&[1i,2,3,4,5]];
-        assert_eq!(v.chunks(6).collect::<Vec<&[int]>>().as_slice(), chunks);
+        assert_eq!(v.chunks(6).collect::<Vec<&[int]>>(), chunks);
 
         let chunks: &[&[int]] = &[&[5i], &[3,4], &[1,2]];
-        assert_eq!(v.chunks(2).rev().collect::<Vec<&[int]>>().as_slice(), chunks);
+        assert_eq!(v.chunks(2).rev().collect::<Vec<&[int]>>(), chunks);
         let mut it = v.chunks(2);
         assert_eq!(it.indexable(), 3);
         let chunk: &[int] = &[1,2];
@@ -2081,7 +2081,7 @@ fn test_mut_last() {
     fn test_to_vec() {
         let xs = box [1u, 2, 3];
         let ys = xs.to_vec();
-        assert_eq!(ys.as_slice(), [1u, 2, 3].as_slice());
+        assert_eq!(ys, [1u, 2, 3]);
     }
 }
 
index ad0a5e76176464fdcd2611adc612d7e284d76b82..6e26962950ba2d7b937360543ef123e4009185ac 100644 (file)
@@ -215,7 +215,7 @@ pub struct Decompositions<'a> {
 impl<'a> Iterator<char> for Decompositions<'a> {
     #[inline]
     fn next(&mut self) -> Option<char> {
-        match self.buffer.as_slice().head() {
+        match self.buffer.head() {
             Some(&(c, 0)) => {
                 self.sorted = false;
                 self.buffer.remove(0);
@@ -913,10 +913,10 @@ fn test_rfind() {
     #[test]
     fn test_collect() {
         let empty = String::from_str("");
-        let s: String = empty.as_slice().chars().collect();
+        let s: String = empty.chars().collect();
         assert_eq!(empty, s);
         let data = String::from_str("ประเทศไทย中");
-        let s: String = data.as_slice().chars().collect();
+        let s: String = data.chars().collect();
         assert_eq!(data, s);
     }
 
@@ -924,7 +924,7 @@ fn test_collect() {
     fn test_into_bytes() {
         let data = String::from_str("asdf");
         let buf = data.into_bytes();
-        assert_eq!(b"asdf", buf.as_slice());
+        assert_eq!(b"asdf", buf);
     }
 
     #[test]
@@ -941,21 +941,21 @@ fn test_find_str() {
         let string = "ประเทศไทย中华Việt Nam";
         let mut data = String::from_str(string);
         data.push_str(string);
-        assert!(data.as_slice().find_str("ไท华").is_none());
-        assert_eq!(data.as_slice().slice(0u, 43u).find_str(""), Some(0u));
-        assert_eq!(data.as_slice().slice(6u, 43u).find_str(""), Some(6u - 6u));
+        assert!(data.find_str("ไท华").is_none());
+        assert_eq!(data.slice(0u, 43u).find_str(""), Some(0u));
+        assert_eq!(data.slice(6u, 43u).find_str(""), Some(6u - 6u));
 
-        assert_eq!(data.as_slice().slice(0u, 43u).find_str("ประ"), Some( 0u));
-        assert_eq!(data.as_slice().slice(0u, 43u).find_str("ทศไ"), Some(12u));
-        assert_eq!(data.as_slice().slice(0u, 43u).find_str("ย中"), Some(24u));
-        assert_eq!(data.as_slice().slice(0u, 43u).find_str("iệt"), Some(34u));
-        assert_eq!(data.as_slice().slice(0u, 43u).find_str("Nam"), Some(40u));
+        assert_eq!(data.slice(0u, 43u).find_str("ประ"), Some( 0u));
+        assert_eq!(data.slice(0u, 43u).find_str("ทศไ"), Some(12u));
+        assert_eq!(data.slice(0u, 43u).find_str("ย中"), Some(24u));
+        assert_eq!(data.slice(0u, 43u).find_str("iệt"), Some(34u));
+        assert_eq!(data.slice(0u, 43u).find_str("Nam"), Some(40u));
 
-        assert_eq!(data.as_slice().slice(43u, 86u).find_str("ประ"), Some(43u - 43u));
-        assert_eq!(data.as_slice().slice(43u, 86u).find_str("ทศไ"), Some(55u - 43u));
-        assert_eq!(data.as_slice().slice(43u, 86u).find_str("ย中"), Some(67u - 43u));
-        assert_eq!(data.as_slice().slice(43u, 86u).find_str("iệt"), Some(77u - 43u));
-        assert_eq!(data.as_slice().slice(43u, 86u).find_str("Nam"), Some(83u - 43u));
+        assert_eq!(data.slice(43u, 86u).find_str("ประ"), Some(43u - 43u));
+        assert_eq!(data.slice(43u, 86u).find_str("ทศไ"), Some(55u - 43u));
+        assert_eq!(data.slice(43u, 86u).find_str("ย中"), Some(67u - 43u));
+        assert_eq!(data.slice(43u, 86u).find_str("iệt"), Some(77u - 43u));
+        assert_eq!(data.slice(43u, 86u).find_str("Nam"), Some(83u - 43u));
     }
 
     #[test]
@@ -987,7 +987,7 @@ macro_rules! test_concat {
         ($expected: expr, $string: expr) => {
             {
                 let s = $string.concat();
-                assert_eq!($expected, s.as_slice());
+                assert_eq!($expected, s);
             }
         }
     }
@@ -1025,7 +1025,7 @@ macro_rules! test_connect {
         ($expected: expr, $string: expr, $delim: expr) => {
             {
                 let s = $string.connect($delim);
-                assert_eq!($expected, s.as_slice());
+                assert_eq!($expected, s);
             }
         }
     }
@@ -1146,7 +1146,7 @@ fn test_replace_2a() {
 
         let a = "ประเ";
         let a2 = "دولة الكويتทศไทย中华";
-        assert_eq!(data.replace(a, repl).as_slice(), a2);
+        assert_eq!(data.replace(a, repl), a2);
     }
 
     #[test]
@@ -1156,7 +1156,7 @@ fn test_replace_2b() {
 
         let b = "ะเ";
         let b2 = "ปรدولة الكويتทศไทย中华";
-        assert_eq!(data.replace(b, repl).as_slice(), b2);
+        assert_eq!(data.replace(b, repl), b2);
     }
 
     #[test]
@@ -1166,7 +1166,7 @@ fn test_replace_2c() {
 
         let c = "中华";
         let c2 = "ประเทศไทยدولة الكويت";
-        assert_eq!(data.replace(c, repl).as_slice(), c2);
+        assert_eq!(data.replace(c, repl), c2);
     }
 
     #[test]
@@ -1175,7 +1175,7 @@ fn test_replace_2d() {
         let repl = "دولة الكويت";
 
         let d = "ไท华";
-        assert_eq!(data.replace(d, repl).as_slice(), data);
+        assert_eq!(data.replace(d, repl), data);
     }
 
     #[test]
@@ -1211,7 +1211,7 @@ fn half_a_million_letter_x() -> String {
         }
         let letters = a_million_letter_x();
         assert!(half_a_million_letter_x() ==
-            String::from_str(letters.as_slice().slice(0u, 3u * 500000u)));
+            String::from_str(letters.slice(0u, 3u * 500000u)));
     }
 
     #[test]
@@ -1450,7 +1450,7 @@ fn test_as_bytes() {
         let b: &[u8] = &[];
         assert_eq!("".as_bytes(), b);
         assert_eq!("abc".as_bytes(), b"abc");
-        assert_eq!("ศไทย中华Việt Nam".as_bytes(), v.as_slice());
+        assert_eq!("ศไทย中华Việt Nam".as_bytes(), v);
     }
 
     #[test]
@@ -1485,7 +1485,6 @@ fn test_subslice_offset() {
 
         let string = "a\nb\nc";
         let lines: Vec<&str> = string.lines().collect();
-        let lines = lines.as_slice();
         assert_eq!(string.subslice_offset(lines[0]), 0);
         assert_eq!(string.subslice_offset(lines[1]), 2);
         assert_eq!(string.subslice_offset(lines[2]), 4);
@@ -2181,10 +2180,10 @@ fn test_graphemes() {
         let s = "a̐éö̲\r\n";
         let gr_inds = s.grapheme_indices(true).collect::<Vec<(uint, &str)>>();
         let b: &[_] = &[(0u, "a̐"), (3, "é"), (6, "ö̲"), (11, "\r\n")];
-        assert_eq!(gr_inds.as_slice(), b);
+        assert_eq!(gr_inds, b);
         let gr_inds = s.grapheme_indices(true).rev().collect::<Vec<(uint, &str)>>();
         let b: &[_] = &[(11, "\r\n"), (6, "ö̲"), (3, "é"), (0u, "a̐")];
-        assert_eq!(gr_inds.as_slice(), b);
+        assert_eq!(gr_inds, b);
         let mut gr_inds_iter = s.grapheme_indices(true);
         {
             let gr_inds = gr_inds_iter.by_ref();
@@ -2200,14 +2199,14 @@ fn test_graphemes() {
         let s = "\n\r\n\r";
         let gr = s.graphemes(true).rev().collect::<Vec<&str>>();
         let b: &[_] = &["\r", "\r\n", "\n"];
-        assert_eq!(gr.as_slice(), b);
+        assert_eq!(gr, b);
     }
 
     #[test]
     fn test_split_strator() {
         fn t(s: &str, sep: &str, u: &[&str]) {
             let v: Vec<&str> = s.split_str(sep).collect();
-            assert_eq!(v.as_slice(), u.as_slice());
+            assert_eq!(v, u);
         }
         t("--1233345--", "12345", &["--1233345--"]);
         t("abc::hello::there", "::", &["abc", "hello", "there"]);
index fbb0bb5c4ce8673cf5fa71d3d34914a65d2ce024..a7545d069602718fbac4efad61f5ef6128c0eaa4 100644 (file)
@@ -559,7 +559,7 @@ pub fn as_bytes<'a>(&'a self) -> &'a [u8] {
     #[inline]
     #[unstable = "the panic conventions for strings are under development"]
     pub fn truncate(&mut self, new_len: uint) {
-        assert!(self.as_slice().is_char_boundary(new_len));
+        assert!(self.is_char_boundary(new_len));
         self.vec.truncate(new_len)
     }
 
@@ -583,7 +583,7 @@ pub fn pop(&mut self) -> Option<char> {
             return None
         }
 
-        let CharRange {ch, next} = self.as_slice().char_range_at_reverse(len);
+        let CharRange {ch, next} = self.char_range_at_reverse(len);
         unsafe {
             self.vec.set_len(next);
         }
@@ -618,7 +618,7 @@ pub fn remove(&mut self, idx: uint) -> Option<char> {
         let len = self.len();
         if idx >= len { return None }
 
-        let CharRange { ch, next } = self.as_slice().char_range_at(idx);
+        let CharRange { ch, next } = self.char_range_at(idx);
         unsafe {
             ptr::copy_memory(self.vec.as_mut_ptr().offset(idx as int),
                              self.vec.as_ptr().offset(next as int),
@@ -643,7 +643,7 @@ pub fn remove(&mut self, idx: uint) -> Option<char> {
     pub fn insert(&mut self, idx: uint, ch: char) {
         let len = self.len();
         assert!(idx <= len);
-        assert!(self.as_slice().is_char_boundary(idx));
+        assert!(self.is_char_boundary(idx));
         self.vec.reserve(4);
         let mut bits = [0, ..4];
         let amt = ch.encode_utf8(&mut bits).unwrap();
@@ -1092,7 +1092,7 @@ fn test_from_utf16() {
 
         for p in pairs.iter() {
             let (s, u) = (*p).clone();
-            let s_as_utf16 = s.as_slice().utf16_units().collect::<Vec<u16>>();
+            let s_as_utf16 = s.utf16_units().collect::<Vec<u16>>();
             let u_as_string = String::from_utf16(u.as_slice()).unwrap();
 
             assert!(str::is_utf16(u.as_slice()));
@@ -1102,7 +1102,7 @@ fn test_from_utf16() {
             assert_eq!(String::from_utf16_lossy(u.as_slice()), s);
 
             assert_eq!(String::from_utf16(s_as_utf16.as_slice()).unwrap(), s);
-            assert_eq!(u_as_string.as_slice().utf16_units().collect::<Vec<u16>>(), u);
+            assert_eq!(u_as_string.utf16_units().collect::<Vec<u16>>(), u);
         }
     }
 
@@ -1162,18 +1162,18 @@ fn test_push_bytes() {
             let mv = s.as_mut_vec();
             mv.push_all(&[b'D']);
         }
-        assert_eq!(s.as_slice(), "ABCD");
+        assert_eq!(s, "ABCD");
     }
 
     #[test]
     fn test_push_str() {
         let mut s = String::new();
         s.push_str("");
-        assert_eq!(s.as_slice().slice_from(0), "");
+        assert_eq!(s.slice_from(0), "");
         s.push_str("abc");
-        assert_eq!(s.as_slice().slice_from(0), "abc");
+        assert_eq!(s.slice_from(0), "abc");
         s.push_str("ประเทศไทย中华Việt Nam");
-        assert_eq!(s.as_slice().slice_from(0), "abcประเทศไทย中华Việt Nam");
+        assert_eq!(s.slice_from(0), "abcประเทศไทย中华Việt Nam");
     }
 
     #[test]
@@ -1184,7 +1184,7 @@ fn test_push() {
         data.push('¢'); // 2 byte
         data.push('€'); // 3 byte
         data.push('𤭢'); // 4 byte
-        assert_eq!(data.as_slice(), "ประเทศไทย中华b¢€𤭢");
+        assert_eq!(data, "ประเทศไทย中华b¢€𤭢");
     }
 
     #[test]
@@ -1195,24 +1195,24 @@ fn test_pop() {
         assert_eq!(data.pop().unwrap(), '¢'); // 2 bytes
         assert_eq!(data.pop().unwrap(), 'b'); // 1 bytes
         assert_eq!(data.pop().unwrap(), '华');
-        assert_eq!(data.as_slice(), "ประเทศไทย中");
+        assert_eq!(data, "ประเทศไทย中");
     }
 
     #[test]
     fn test_str_truncate() {
         let mut s = String::from_str("12345");
         s.truncate(5);
-        assert_eq!(s.as_slice(), "12345");
+        assert_eq!(s, "12345");
         s.truncate(3);
-        assert_eq!(s.as_slice(), "123");
+        assert_eq!(s, "123");
         s.truncate(0);
-        assert_eq!(s.as_slice(), "");
+        assert_eq!(s, "");
 
         let mut s = String::from_str("12345");
-        let p = s.as_slice().as_ptr();
+        let p = s.as_ptr();
         s.truncate(3);
         s.push_str("6");
-        let p_ = s.as_slice().as_ptr();
+        let p_ = s.as_ptr();
         assert_eq!(p_, p);
     }
 
@@ -1235,7 +1235,7 @@ fn test_str_clear() {
         let mut s = String::from_str("12345");
         s.clear();
         assert_eq!(s.len(), 0);
-        assert_eq!(s.as_slice(), "");
+        assert_eq!(s, "");
     }
 
     #[test]
@@ -1244,7 +1244,7 @@ fn test_str_add() {
         let b = a + "2";
         let b = b + String::from_str("2");
         assert_eq!(b.len(), 7);
-        assert_eq!(b.as_slice(), "1234522");
+        assert_eq!(b, "1234522");
     }
 
     #[test]
@@ -1252,11 +1252,11 @@ fn remove() {
         let mut s = "ศไทย中华Việt Nam; foobar".to_string();;
         assert_eq!(s.remove(0), Some('ศ'));
         assert_eq!(s.len(), 33);
-        assert_eq!(s.as_slice(), "ไทย中华Việt Nam; foobar");
+        assert_eq!(s, "ไทย中华Việt Nam; foobar");
         assert_eq!(s.remove(33), None);
         assert_eq!(s.remove(300), None);
         assert_eq!(s.remove(17), Some('ệ'));
-        assert_eq!(s.as_slice(), "ไทย中华Vit Nam; foobar");
+        assert_eq!(s, "ไทย中华Vit Nam; foobar");
     }
 
     #[test] #[should_fail]
@@ -1268,9 +1268,9 @@ fn remove_bad() {
     fn insert() {
         let mut s = "foobar".to_string();
         s.insert(0, 'ệ');
-        assert_eq!(s.as_slice(), "ệfoobar");
+        assert_eq!(s, "ệfoobar");
         s.insert(6, 'ย');
-        assert_eq!(s.as_slice(), "ệfooยbar");
+        assert_eq!(s, "ệfooยbar");
     }
 
     #[test] #[should_fail] fn insert_bad1() { "".to_string().insert(1, 't'); }
index 2396cf8cec67ce20d235031f3a44e8888728b2c7..e2411ced632afae726a9dd312fec8305b71a9ef9 100644 (file)
@@ -798,7 +798,7 @@ pub fn truncate(&mut self, len: uint) {
                 // decrement len before the read(), so a panic on Drop doesn't
                 // re-drop the just-failed value.
                 self.len -= 1;
-                ptr::read(self.as_slice().unsafe_get(self.len));
+                ptr::read(self.unsafe_get(self.len));
             }
         }
     }
@@ -1091,7 +1091,7 @@ pub fn pop(&mut self) -> Option<T> {
         } else {
             unsafe {
                 self.len -= 1;
-                Some(ptr::read(self.as_slice().unsafe_get(self.len())))
+                Some(ptr::read(self.unsafe_get(self.len())))
             }
         }
     }
@@ -1779,7 +1779,7 @@ fn drop(&mut self) {
     #[test]
     fn test_as_vec() {
         let xs = [1u8, 2u8, 3u8];
-        assert_eq!(as_vec(&xs).as_slice(), xs.as_slice());
+        assert_eq!(as_vec(&xs).as_slice(), xs);
     }
 
     #[test]
@@ -1875,7 +1875,7 @@ fn test_slice_from_mut() {
             }
         }
 
-        assert!(values.as_slice() == [1, 2, 5, 6, 7]);
+        assert!(values == [1, 2, 5, 6, 7]);
     }
 
     #[test]
@@ -1889,7 +1889,7 @@ fn test_slice_to_mut() {
             }
         }
 
-        assert!(values.as_slice() == [2, 3, 3, 4, 5]);
+        assert!(values == [2, 3, 3, 4, 5]);
     }
 
     #[test]
@@ -2019,7 +2019,6 @@ fn test_zip_unzip() {
 
         let (left, right) = unzip(z1.iter().map(|&x| x));
 
-        let (left, right) = (left.as_slice(), right.as_slice());
         assert_eq!((1, 4), (left[0], right[0]));
         assert_eq!((2, 5), (left[1], right[1]));
         assert_eq!((3, 6), (left[2], right[2]));
@@ -2153,7 +2152,7 @@ fn test_map_in_place_incompatible_types_fail() {
     #[test]
     fn test_map_in_place() {
         let v = vec![0u, 1, 2];
-        assert_eq!(v.map_in_place(|i: uint| i as int - 1).as_slice(), [-1i, 0, 1].as_slice());
+        assert_eq!(v.map_in_place(|i: uint| i as int - 1), [-1i, 0, 1]);
     }
 
     #[test]
@@ -2161,7 +2160,7 @@ fn test_map_in_place_zero_sized() {
         let v = vec![(), ()];
         #[deriving(PartialEq, Show)]
         struct ZeroSized;
-        assert_eq!(v.map_in_place(|_| ZeroSized).as_slice(), [ZeroSized, ZeroSized].as_slice());
+        assert_eq!(v.map_in_place(|_| ZeroSized), [ZeroSized, ZeroSized]);
     }
 
     #[test]
@@ -2198,7 +2197,7 @@ fn test_move_items_zero_sized() {
     fn test_into_boxed_slice() {
         let xs = vec![1u, 2, 3];
         let ys = xs.into_boxed_slice();
-        assert_eq!(ys.as_slice(), [1u, 2, 3].as_slice());
+        assert_eq!(ys.as_slice(), [1u, 2, 3]);
     }
 
     #[bench]
index 986e7ef5bc24e9d7d4e97de79ec32cc4bc511a67..3be662c071c1606110dd82e14831c08ec1cef0b5 100644 (file)
@@ -870,7 +870,6 @@ fn test_show() {
         map.insert(3, 4i);
 
         let map_str = map.to_string();
-        let map_str = map_str.as_slice();
         assert!(map_str == "{1: 2, 3: 4}" || map_str == "{3: 4, 1: 2}");
         assert_eq!(format!("{}", empty), "{}".to_string());
     }