Skip to content

Commit f245929

Browse files
seanmonstaralexcrichton
authored andcommitted
collections: change bounds of SliceConcatExt implementations to use Borrow instead of AsRef
Conflicts: src/libcollections/slice.rs src/libcollections/str.rs
1 parent 91f1e51 commit f245929

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

src/libcollections/slice.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@
8080
#![stable(feature = "rust1", since = "1.0.0")]
8181

8282
use alloc::boxed::Box;
83-
use core::convert::AsRef;
8483
use core::clone::Clone;
8584
use core::cmp::Ordering::{self, Greater, Less};
8685
use core::cmp::{self, Ord, PartialEq};
@@ -1028,23 +1027,23 @@ pub trait SliceConcatExt<T: ?Sized, U> {
10281027
fn connect(&self, sep: &T) -> U;
10291028
}
10301029

1031-
impl<T: Clone, V: AsRef<[T]>> SliceConcatExt<T, Vec<T>> for [V] {
1030+
impl<T: Clone, V: Borrow<[T]>> SliceConcatExt<T, Vec<T>> for [V] {
10321031
fn concat(&self) -> Vec<T> {
1033-
let size = self.iter().fold(0, |acc, v| acc + v.as_ref().len());
1032+
let size = self.iter().fold(0, |acc, v| acc + v.borrow().len());
10341033
let mut result = Vec::with_capacity(size);
10351034
for v in self {
1036-
result.push_all(v.as_ref())
1035+
result.push_all(v.borrow())
10371036
}
10381037
result
10391038
}
10401039

10411040
fn connect(&self, sep: &T) -> Vec<T> {
1042-
let size = self.iter().fold(0, |acc, v| acc + v.as_ref().len());
1041+
let size = self.iter().fold(0, |acc, v| acc + v.borrow().len());
10431042
let mut result = Vec::with_capacity(size + self.len());
10441043
let mut first = true;
10451044
for v in self {
10461045
if first { first = false } else { result.push(sep.clone()) }
1047-
result.push_all(v.as_ref())
1046+
result.push_all(v.borrow())
10481047
}
10491048
result
10501049
}

src/libcollections/str.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ use core::str::pattern::Pattern;
6161
use core::str::pattern::{Searcher, ReverseSearcher, DoubleEndedSearcher};
6262
use unicode::str::{UnicodeStr, Utf16Encoder};
6363

64-
use core::convert::AsRef;
6564
use vec_deque::VecDeque;
6665
use borrow::{Borrow, ToOwned};
6766
use string::String;
@@ -85,18 +84,18 @@ pub use core::str::pattern;
8584
Section: Creating a string
8685
*/
8786

88-
impl<S: AsRef<str>> SliceConcatExt<str, String> for [S] {
87+
impl<S: Borrow<str>> SliceConcatExt<str, String> for [S] {
8988
fn concat(&self) -> String {
9089
if self.is_empty() {
9190
return String::new();
9291
}
9392

9493
// `len` calculation may overflow but push_str will check boundaries
95-
let len = self.iter().map(|s| s.as_ref().len()).sum();
94+
let len = self.iter().map(|s| s.borrow().len()).sum();
9695
let mut result = String::with_capacity(len);
9796

9897
for s in self {
99-
result.push_str(s.as_ref())
98+
result.push_str(s.borrow())
10099
}
101100

102101
result
@@ -115,7 +114,7 @@ impl<S: AsRef<str>> SliceConcatExt<str, String> for [S] {
115114
// this is wrong without the guarantee that `self` is non-empty
116115
// `len` calculation may overflow but push_str but will check boundaries
117116
let len = sep.len() * (self.len() - 1)
118-
+ self.iter().map(|s| s.as_ref().len()).sum::<usize>();
117+
+ self.iter().map(|s| s.borrow().len()).sum::<usize>();
119118
let mut result = String::with_capacity(len);
120119
let mut first = true;
121120

@@ -125,7 +124,7 @@ impl<S: AsRef<str>> SliceConcatExt<str, String> for [S] {
125124
} else {
126125
result.push_str(sep);
127126
}
128-
result.push_str(s.as_ref());
127+
result.push_str(s.borrow());
129128
}
130129
result
131130
}

0 commit comments

Comments
 (0)