}
}
-#[allow(missing_docs)]
-pub trait VectorVector<T> 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<T>`.
- fn concat_vec(&self) -> Vec<T>;
-
- /// Concatenate a vector of vectors, placing a given separator between each.
- fn connect_vec(&self, sep: &T) -> Vec<T>;
+#[unstable = "U should be an associated type"]
+/// An extension trait for concatenating slices
+pub trait SliceConcatExt<Sized? T, U> for Sized? {
+ /// Flattens a slice of `T` into a single value `U`.
+ #[stable]
+ fn concat(&self) -> U;
+
+ #[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<T>> VectorVector<T> for [V] {
- fn concat_vec(&self) -> Vec<T> {
+impl<T: Clone, V: AsSlice<T>> SliceConcatExt<T, Vec<T>> for [V] {
+ fn concat(&self) -> Vec<T> {
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() {
result
}
- fn connect_vec(&self, sep: &T) -> Vec<T> {
+ fn connect(&self, sep: &T) -> Vec<T> {
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;
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};
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<S: Str> StrVector for [S] {
+impl<S: Str> SliceConcatExt<str, String> for [S] {
fn concat(&self) -> String {
if self.is_empty() {
return String::new();
}
}
-impl<S: Str, T: AsSlice<S>> 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<S: Str> SliceConcatExt<str, String> for Vec<S> {
+ fn concat(&self) -> String { self[].concat() }
+ fn connect(&self, sep: &str) -> String { self[].connect(sep) }
}
/*
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;
}
}
}
- Some(Path::new(comps.connect_vec(&SEP_BYTE)))
+ Some(Path::new(comps.as_slice().connect(&SEP_BYTE)))
}
}
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;
#[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};