diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs index ec522ae9e5a..5bc99889f2f 100644 --- a/src/libcollections/slice.rs +++ b/src/libcollections/slice.rs @@ -993,19 +993,31 @@ impl OrdSliceExt for [T] { } } -#[allow(missing_docs)] -pub trait VectorVector for Sized? { - // FIXME #5898: calling these .concat and .connect conflicts with - // StrVector::con{cat,nect}, since they have generic contents. - /// Flattens a vector of vectors of `T` into a single `Vec`. - fn concat_vec(&self) -> Vec; +#[unstable = "U should be an associated type"] +/// An extension trait for concatenating slices +pub trait SliceConcatExt for Sized? { + /// Flattens a slice of `T` into a single value `U`. + #[stable] + fn concat(&self) -> U; - /// Concatenate a vector of vectors, placing a given separator between each. - fn connect_vec(&self, sep: &T) -> Vec; + #[deprecated = "renamed to concat"] + fn concat_vec(&self) -> U { + self.concat() + } + + /// Flattens a slice of `T` into a single value `U`, placing a + /// given seperator between each. + #[stable] + fn connect(&self, sep: &T) -> U; + + #[deprecated = "renamed to connect"] + fn connect_vec(&self, sep: &T) -> U { + self.connect(sep) + } } -impl<'a, T: Clone, V: AsSlice> VectorVector for [V] { - fn concat_vec(&self) -> Vec { +impl> SliceConcatExt> for [V] { + fn concat(&self) -> Vec { let size = self.iter().fold(0u, |acc, v| acc + v.as_slice().len()); let mut result = Vec::with_capacity(size); for v in self.iter() { @@ -1014,7 +1026,7 @@ impl<'a, T: Clone, V: AsSlice> VectorVector for [V] { result } - fn connect_vec(&self, sep: &T) -> Vec { + fn connect(&self, sep: &T) -> Vec { let size = self.iter().fold(0u, |acc, v| acc + v.as_slice().len()); let mut result = Vec::with_capacity(size + self.len()); let mut first = true; diff --git a/src/libcollections/str.rs b/src/libcollections/str.rs index 7c7a7e19a2f..60449c817cb 100644 --- a/src/libcollections/str.rs +++ b/src/libcollections/str.rs @@ -77,6 +77,7 @@ use slice::SliceExt; use string::String; use unicode; use vec::Vec; +use slice::SliceConcatExt; pub use core::str::{from_utf8, CharEq, Chars, CharIndices}; pub use core::str::{Bytes, CharSplits, is_utf8}; @@ -93,36 +94,7 @@ pub use core::str::{SplitN, RSplitN}; Section: Creating a string */ -/// Methods for vectors of strings. -#[unstable = "functionality may be replaced with iterators"] -pub trait StrVector for Sized? { - /// Concatenates a vector of strings. - /// - /// # Examples - /// - /// ```rust - /// let first = "Restaurant at the End of the".to_string(); - /// let second = " Universe".to_string(); - /// let string_vec = vec![first, second]; - /// assert_eq!(string_vec.concat(), "Restaurant at the End of the Universe".to_string()); - /// ``` - fn concat(&self) -> String; - - /// Concatenates a vector of strings, placing a given separator between each. - /// - /// # Examples - /// - /// ```rust - /// let first = "Roast".to_string(); - /// let second = "Sirloin Steak".to_string(); - /// let string_vec = vec![first, second]; - /// assert_eq!(string_vec.connect(", "), "Roast, Sirloin Steak".to_string()); - /// ``` - fn connect(&self, sep: &str) -> String; -} - -#[allow(deprecated)] -impl StrVector for [S] { +impl SliceConcatExt for [S] { fn concat(&self) -> String { if self.is_empty() { return String::new(); @@ -169,16 +141,9 @@ impl StrVector for [S] { } } -impl> StrVector for T { - #[inline] - fn concat(&self) -> String { - self.as_slice().concat() - } - - #[inline] - fn connect(&self, sep: &str) -> String { - self.as_slice().connect(sep) - } +impl SliceConcatExt for Vec { + fn concat(&self) -> String { self[].concat() } + fn connect(&self, sep: &str) -> String { self[].connect(sep) } } /* diff --git a/src/libstd/path/posix.rs b/src/libstd/path/posix.rs index 60f147eac9b..41cbaa2b807 100644 --- a/src/libstd/path/posix.rs +++ b/src/libstd/path/posix.rs @@ -22,7 +22,7 @@ use option::Option::{None, Some}; use kinds::Sized; use str::{FromStr, Str}; use str; -use slice::{CloneSliceExt, Splits, AsSlice, VectorVector, +use slice::{CloneSliceExt, Split, AsSlice, SliceConcatExt, PartialEqSliceExt, SliceExt}; use vec::Vec; @@ -306,7 +306,7 @@ impl GenericPath for Path { } } } - Some(Path::new(comps.connect_vec(&SEP_BYTE))) + Some(Path::new(comps.as_slice().connect(&SEP_BYTE))) } } diff --git a/src/libstd/path/windows.rs b/src/libstd/path/windows.rs index 879a96e8026..165d2c32416 100644 --- a/src/libstd/path/windows.rs +++ b/src/libstd/path/windows.rs @@ -25,8 +25,8 @@ use iter::{Iterator, IteratorExt, Map, repeat}; use mem; use option::Option; use option::Option::{Some, None}; -use slice::SliceExt; -use str::{SplitTerminator, FromStr, StrVector, StrExt}; +use slice::{AsSlice, SliceExt, SliceConcatExt}; +use str::{CharSplits, FromStr, Str, StrAllocating, StrPrelude}; use string::{String, ToString}; use unicode::char::UnicodeChar; use vec::Vec; diff --git a/src/libstd/prelude.rs b/src/libstd/prelude.rs index 11eb569e5b5..f016683e3d0 100644 --- a/src/libstd/prelude.rs +++ b/src/libstd/prelude.rs @@ -80,10 +80,9 @@ #[doc(no_inline)] pub use core::prelude::{Tuple1, Tuple2, Tuple3, Tuple4}; #[doc(no_inline)] pub use core::prelude::{Tuple5, Tuple6, Tuple7, Tuple8}; #[doc(no_inline)] pub use core::prelude::{Tuple9, Tuple10, Tuple11, Tuple12}; -#[doc(no_inline)] pub use str::{Str, StrVector}; -#[doc(no_inline)] pub use str::StrExt; +#[doc(no_inline)] pub use str::{Str, StrExt}; #[doc(no_inline)] pub use slice::AsSlice; -#[doc(no_inline)] pub use slice::{VectorVector, PartialEqSliceExt}; +#[doc(no_inline)] pub use slice::{SliceConcatExt, PartialEqSliceExt}; #[doc(no_inline)] pub use slice::{CloneSliceExt, OrdSliceExt, SliceExt}; #[doc(no_inline)] pub use slice::{BoxedSliceExt}; #[doc(no_inline)] pub use string::{IntoString, String, ToString};