Skip to content

Commit 5a83fa2

Browse files
committedMay 6, 2015
Auto merge of rust-lang#25120 - bluss:sliceconcatext, r=alexcrichton
collections: Convert SliceConcatExt to use associated types Coherence now allows this, we have `SliceConcatExt<T> for [V] where T: Sized + Clone` and` SliceConcatExt<str> for [S]`, these don't conflict because str is never Sized.
2 parents fc45fd9 + 2ca77f1 commit 5a83fa2

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed
 

‎src/libcollections/slice.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -996,9 +996,13 @@ impl<T> [T] {
996996
////////////////////////////////////////////////////////////////////////////////
997997
// Extension traits for slices over specific kinds of data
998998
////////////////////////////////////////////////////////////////////////////////
999-
#[unstable(feature = "collections", reason = "U should be an associated type")]
999+
#[unstable(feature = "collections", reason = "recently changed")]
10001000
/// An extension trait for concatenating slices
1001-
pub trait SliceConcatExt<T: ?Sized, U> {
1001+
pub trait SliceConcatExt<T: ?Sized> {
1002+
#[unstable(feature = "collections", reason = "recently changed")]
1003+
/// The resulting type after concatenation
1004+
type Output;
1005+
10021006
/// Flattens a slice of `T` into a single value `U`.
10031007
///
10041008
/// # Examples
@@ -1007,7 +1011,7 @@ pub trait SliceConcatExt<T: ?Sized, U> {
10071011
/// assert_eq!(["hello", "world"].concat(), "helloworld");
10081012
/// ```
10091013
#[stable(feature = "rust1", since = "1.0.0")]
1010-
fn concat(&self) -> U;
1014+
fn concat(&self) -> Self::Output;
10111015

10121016
/// Flattens a slice of `T` into a single value `U`, placing a given separator between each.
10131017
///
@@ -1017,10 +1021,12 @@ pub trait SliceConcatExt<T: ?Sized, U> {
10171021
/// assert_eq!(["hello", "world"].connect(" "), "hello world");
10181022
/// ```
10191023
#[stable(feature = "rust1", since = "1.0.0")]
1020-
fn connect(&self, sep: &T) -> U;
1024+
fn connect(&self, sep: &T) -> Self::Output;
10211025
}
10221026

1023-
impl<T: Clone, V: AsRef<[T]>> SliceConcatExt<T, Vec<T>> for [V] {
1027+
impl<T: Clone, V: AsRef<[T]>> SliceConcatExt<T> for [V] {
1028+
type Output = Vec<T>;
1029+
10241030
fn concat(&self) -> Vec<T> {
10251031
let size = self.iter().fold(0, |acc, v| acc + v.as_ref().len());
10261032
let mut result = Vec::with_capacity(size);

‎src/libcollections/str.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ pub use core::str::pattern;
8383
Section: Creating a string
8484
*/
8585

86-
impl<S: AsRef<str>> SliceConcatExt<str, String> for [S] {
86+
impl<S: AsRef<str>> SliceConcatExt<str> for [S] {
87+
type Output = String;
88+
8789
fn concat(&self) -> String {
8890
if self.is_empty() {
8991
return String::new();

0 commit comments

Comments
 (0)
Please sign in to comment.