diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs index 107dc3e5c28b7..c0f7e0981c8f7 100644 --- a/src/libcollections/slice.rs +++ b/src/libcollections/slice.rs @@ -108,19 +108,19 @@ pub use core::slice::{Found, NotFound}; // Functional utilities +#[experimental = "U should be an associated type"] #[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; +pub trait Concat for Sized? { + /// Flattens a slice of `T` into a single value `U`. + fn concat(&self) -> U; - /// Concatenate a vector of vectors, placing a given separator between each. - fn connect_vec(&self, sep: &T) -> Vec; + /// Flattens a slice of `T` into a single value `U`, placing a + /// given seperator between each. + fn connect(&self, sep: &T) -> U; } -impl> VectorVector for [V] { - fn concat_vec(&self) -> Vec { +impl> Concat> 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() { @@ -129,7 +129,7 @@ impl> 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; @@ -141,6 +141,28 @@ impl> VectorVector for [V] { } } +#[allow(missing_docs)] +#[deprecated] +pub trait VectorVector for Sized? { + /// Deprecated: use `concat` instead. + #[deprecated = "use concat instead"] + fn concat_vec(&self) -> Vec; + + /// Deprecated: use `connect` instead. + #[deprecated = "use connect instead"] + fn connect_vec(&self, sep: &T) -> Vec; +} + +impl> VectorVector for [V] { + fn concat_vec(&self) -> Vec { + self.concat() + } + + fn connect_vec(&self, sep: &T) -> Vec { + self.connect(sep) + } +} + /// An iterator that yields the element swaps needed to produce /// a sequence of all possible permutations for an indexed sequence of /// elements. Each permutation is only a single swap apart. diff --git a/src/libcollections/str.rs b/src/libcollections/str.rs index 5380f1cc1cd08..455a4cdf9a7a1 100644 --- a/src/libcollections/str.rs +++ b/src/libcollections/str.rs @@ -55,7 +55,6 @@ use core::default::Default; use core::fmt; use core::cmp; use core::iter::AdditiveIterator; -use core::kinds::Sized; use core::prelude::{Char, Clone, Eq, Equiv, ImmutableSlice}; use core::prelude::{Iterator, MutableSlice, None, Option, Ord, Ordering}; use core::prelude::{PartialEq, PartialOrd, Result, AsSlice, Some, Tuple2}; @@ -66,6 +65,7 @@ use ringbuf::RingBuf; use string::String; use unicode; use vec::Vec; +use slice::Concat; pub use core::str::{from_utf8, CharEq, Chars, CharOffsets}; pub use core::str::{Bytes, CharSplits}; @@ -80,34 +80,7 @@ pub use unicode::str::{UnicodeStrSlice, Words, Graphemes, GraphemeIndices}; Section: Creating a string */ -/// Methods for vectors of strings. -pub trait StrVector for Sized? { - /// Concatenates a vector of strings. - /// - /// # Example - /// - /// ```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. - /// - /// # Example - /// - /// ```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; -} - -impl StrVector for [S] { +impl Concat for [S] { fn concat(&self) -> String { if self.is_empty() { return String::new(); @@ -154,16 +127,9 @@ impl StrVector for [S] { } } -impl StrVector for Vec { - #[inline] - fn concat(&self) -> String { - self.as_slice().concat() - } - - #[inline] - fn connect(&self, sep: &str) -> String { - self.as_slice().connect(sep) - } +impl Concat 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 e090d9d709801..3f0c431a0f41f 100644 --- a/src/libstd/path/posix.rs +++ b/src/libstd/path/posix.rs @@ -20,7 +20,7 @@ use iter::{DoubleEndedIterator, AdditiveIterator, Extendable, Iterator, Map}; use option::{Option, None, Some}; use str::Str; use str; -use slice::{CloneableVector, Splits, AsSlice, VectorVector, +use slice::{CloneableVector, Splits, AsSlice, Concat, ImmutablePartialEqSlice, ImmutableSlice}; use vec::Vec; @@ -315,7 +315,7 @@ impl GenericPath for Path { } } } - Some(Path::new(comps.as_slice().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 f0d1ecf9d24bc..66071c663ca17 100644 --- a/src/libstd/path/windows.rs +++ b/src/libstd/path/windows.rs @@ -22,8 +22,8 @@ use io::Writer; use iter::{AdditiveIterator, DoubleEndedIterator, Extendable, Iterator, Map}; use mem; use option::{Option, Some, None}; -use slice::{AsSlice, ImmutableSlice}; -use str::{CharSplits, Str, StrAllocating, StrVector, StrSlice}; +use slice::{AsSlice, ImmutableSlice, Concat}; +use str::{CharSplits, Str, StrAllocating, StrSlice}; use string::String; use unicode::char::UnicodeChar; use vec::Vec; diff --git a/src/libstd/prelude.rs b/src/libstd/prelude.rs index b2ff29c0f7eef..2592e4bfdab01 100644 --- a/src/libstd/prelude.rs +++ b/src/libstd/prelude.rs @@ -76,7 +76,7 @@ #[doc(no_inline)] pub use path::{GenericPath, Path, PosixPath, WindowsPath}; #[doc(no_inline)] pub use ptr::{RawPtr, RawMutPtr}; #[doc(no_inline)] pub use io::{Buffer, Writer, Reader, Seek}; -#[doc(no_inline)] pub use str::{Str, StrVector, StrSlice}; +#[doc(no_inline)] pub use str::{Str, StrSlice}; #[doc(no_inline)] pub use str::{IntoMaybeOwned, StrAllocating, UnicodeStrSlice}; #[doc(no_inline)] pub use to_string::{ToString, IntoStr}; #[doc(no_inline)] pub use tuple::{Tuple1, Tuple2, Tuple3, Tuple4}; @@ -86,7 +86,7 @@ #[doc(no_inline)] pub use slice::{MutableCloneableSlice, MutableOrdSlice}; #[doc(no_inline)] pub use slice::{ImmutableSlice, MutableSlice}; #[doc(no_inline)] pub use slice::{ImmutablePartialEqSlice, ImmutableOrdSlice}; -#[doc(no_inline)] pub use slice::{AsSlice, VectorVector, BoxedSlice}; +#[doc(no_inline)] pub use slice::{AsSlice, Concat, VectorVector, BoxedSlice}; #[doc(no_inline)] pub use slice::MutableSliceAllocating; #[doc(no_inline)] pub use string::String; #[doc(no_inline)] pub use vec::Vec;