about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSean McArthur <sean.monstar@gmail.com>2015-05-08 17:13:35 -0700
committerSean McArthur <sean.monstar@gmail.com>2015-05-08 17:13:54 -0700
commit8e491ef0193f48fc000ff62c75544f8dcaa6548d (patch)
tree188e0a36f82c2b0a0daf64a32f8bbd5f9d3de22d
parent093ebd5a62d77678046b5e56420d46df37a97129 (diff)
downloadrust-8e491ef0193f48fc000ff62c75544f8dcaa6548d.tar.gz
rust-8e491ef0193f48fc000ff62c75544f8dcaa6548d.zip
collections: change bounds of SliceConcatExt implementations to use Borrow instead of AsRef
-rw-r--r--src/libcollections/slice.rs11
-rw-r--r--src/libcollections/str.rs11
2 files changed, 10 insertions, 12 deletions
diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs
index 8eb7995c422..b9e9800f7a0 100644
--- a/src/libcollections/slice.rs
+++ b/src/libcollections/slice.rs
@@ -80,7 +80,6 @@
 #![stable(feature = "rust1", since = "1.0.0")]
 
 use alloc::boxed::Box;
-use core::convert::AsRef;
 use core::clone::Clone;
 use core::cmp::Ordering::{self, Greater, Less};
 use core::cmp::{self, Ord, PartialEq};
@@ -1024,25 +1023,25 @@ pub trait SliceConcatExt<T: ?Sized> {
     fn connect(&self, sep: &T) -> Self::Output;
 }
 
-impl<T: Clone, V: AsRef<[T]>> SliceConcatExt<T> for [V] {
+impl<T: Clone, V: Borrow<[T]>> SliceConcatExt<T> for [V] {
     type Output = Vec<T>;
 
     fn concat(&self) -> Vec<T> {
-        let size = self.iter().fold(0, |acc, v| acc + v.as_ref().len());
+        let size = self.iter().fold(0, |acc, v| acc + v.borrow().len());
         let mut result = Vec::with_capacity(size);
         for v in self {
-            result.push_all(v.as_ref())
+            result.push_all(v.borrow())
         }
         result
     }
 
     fn connect(&self, sep: &T) -> Vec<T> {
-        let size = self.iter().fold(0, |acc, v| acc + v.as_ref().len());
+        let size = self.iter().fold(0, |acc, v| acc + v.borrow().len());
         let mut result = Vec::with_capacity(size + self.len());
         let mut first = true;
         for v in self {
             if first { first = false } else { result.push(sep.clone()) }
-            result.push_all(v.as_ref())
+            result.push_all(v.borrow())
         }
         result
     }
diff --git a/src/libcollections/str.rs b/src/libcollections/str.rs
index da1b4dcddfc..baef6ba6f01 100644
--- a/src/libcollections/str.rs
+++ b/src/libcollections/str.rs
@@ -59,7 +59,6 @@ use core::str::pattern::Pattern;
 use core::str::pattern::{Searcher, ReverseSearcher, DoubleEndedSearcher};
 use rustc_unicode::str::{UnicodeStr, Utf16Encoder};
 
-use core::convert::AsRef;
 use vec_deque::VecDeque;
 use borrow::{Borrow, ToOwned};
 use string::String;
@@ -83,7 +82,7 @@ pub use core::str::pattern;
 Section: Creating a string
 */
 
-impl<S: AsRef<str>> SliceConcatExt<str> for [S] {
+impl<S: Borrow<str>> SliceConcatExt<str> for [S] {
     type Output = String;
 
     fn concat(&self) -> String {
@@ -92,11 +91,11 @@ impl<S: AsRef<str>> SliceConcatExt<str> for [S] {
         }
 
         // `len` calculation may overflow but push_str will check boundaries
-        let len = self.iter().map(|s| s.as_ref().len()).sum();
+        let len = self.iter().map(|s| s.borrow().len()).sum();
         let mut result = String::with_capacity(len);
 
         for s in self {
-            result.push_str(s.as_ref())
+            result.push_str(s.borrow())
         }
 
         result
@@ -115,7 +114,7 @@ impl<S: AsRef<str>> SliceConcatExt<str> for [S] {
         // this is wrong without the guarantee that `self` is non-empty
         // `len` calculation may overflow but push_str but will check boundaries
         let len = sep.len() * (self.len() - 1)
-            + self.iter().map(|s| s.as_ref().len()).sum::<usize>();
+            + self.iter().map(|s| s.borrow().len()).sum::<usize>();
         let mut result = String::with_capacity(len);
         let mut first = true;
 
@@ -125,7 +124,7 @@ impl<S: AsRef<str>> SliceConcatExt<str> for [S] {
             } else {
                 result.push_str(sep);
             }
-            result.push_str(s.as_ref());
+            result.push_str(s.borrow());
         }
         result
     }