From c356e3ba6a12c3294a9a428ef9120cff9306bf4b Mon Sep 17 00:00:00 2001 From: Marvin Löbel Date: Fri, 28 Mar 2014 20:42:34 +0100 Subject: Removed deprecated functions `map` and `flat_map` for vectors and slices. --- src/libstd/ascii.rs | 4 +-- src/libstd/io/net/addrinfo.rs | 5 +-- src/libstd/slice.rs | 81 +------------------------------------------ src/libstd/vec.rs | 7 ---- 4 files changed, 6 insertions(+), 91 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/ascii.rs b/src/libstd/ascii.rs index 85df875dc1d..57f7d183458 100644 --- a/src/libstd/ascii.rs +++ b/src/libstd/ascii.rs @@ -285,12 +285,12 @@ impl<'a> AsciiStr for &'a [Ascii] { #[inline] fn to_lower(&self) -> ~[Ascii] { - self.map(|a| a.to_lower()) + self.iter().map(|a| a.to_lower()).collect() } #[inline] fn to_upper(&self) -> ~[Ascii] { - self.map(|a| a.to_upper()) + self.iter().map(|a| a.to_upper()).collect() } #[inline] diff --git a/src/libstd/io/net/addrinfo.rs b/src/libstd/io/net/addrinfo.rs index f16db6e76c9..bf573bfaed8 100644 --- a/src/libstd/io/net/addrinfo.rs +++ b/src/libstd/io/net/addrinfo.rs @@ -19,11 +19,12 @@ getaddrinfo() #![allow(missing_doc)] +use iter::Iterator; use io::IoResult; use io::net::ip::{SocketAddr, IpAddr}; use option::{Option, Some, None}; use rt::rtio::{IoFactory, LocalIo}; -use slice::ImmutableVector; +use slice::OwnedVector; /// Hints to the types of sockets that are desired when looking up hosts pub enum SocketType { @@ -73,7 +74,7 @@ pub struct Info { /// Easy name resolution. Given a hostname, returns the list of IP addresses for /// that hostname. pub fn get_host_addresses(host: &str) -> IoResult<~[IpAddr]> { - lookup(Some(host), None, None).map(|a| a.map(|i| i.address.ip)) + lookup(Some(host), None, None).map(|a| a.move_iter().map(|i| i.address.ip).collect()) } /// Full-fleged resolution. This function will perform a synchronous call to diff --git a/src/libstd/slice.rs b/src/libstd/slice.rs index b5055dfe8b3..4a720aefa4e 100644 --- a/src/libstd/slice.rs +++ b/src/libstd/slice.rs @@ -348,16 +348,6 @@ pub fn append_one(lhs: ~[T], x: T) -> ~[T] { // Functional utilities -/** - * Apply a function to each element of a vector and return a concatenation - * of each result vector - */ -pub fn flat_map(v: &[T], f: |t: &T| -> ~[U]) -> ~[U] { - let mut result = ~[]; - for elem in v.iter() { result.push_all_move(f(elem)); } - result -} - #[allow(missing_doc)] pub trait VectorVector { // FIXME #5898: calling these .concat and .connect conflicts with @@ -902,11 +892,7 @@ pub trait ImmutableVector<'a, T> { fn initn(&self, n: uint) -> &'a [T]; /// Returns the last element of a vector, or `None` if it is empty. fn last(&self) -> Option<&'a T>; - /** - * Apply a function to each element of a vector and return a concatenation - * of each result vector - */ - fn flat_map(&self, f: |t: &T| -> ~[U]) -> ~[U]; + /// Returns a pointer to the element at the given index, without doing /// bounds checking. unsafe fn unsafe_ref(self, index: uint) -> &'a T; @@ -935,11 +921,6 @@ pub trait ImmutableVector<'a, T> { */ fn bsearch(&self, f: |&T| -> Ordering) -> Option; - /// Deprecated, use iterators where possible - /// (`self.iter().map(f)`). Apply a function to each element - /// of a vector and return the results. - fn map(&self, |t: &T| -> U) -> ~[U]; - /** * Returns a mutable reference to the first element in this slice * and adjusts the slice in place so that it no longer contains @@ -1094,11 +1075,6 @@ impl<'a,T> ImmutableVector<'a, T> for &'a [T] { if self.len() == 0 { None } else { Some(&self[self.len() - 1]) } } - #[inline] - fn flat_map(&self, f: |t: &T| -> ~[U]) -> ~[U] { - flat_map(*self, f) - } - #[inline] unsafe fn unsafe_ref(self, index: uint) -> &'a T { transmute(self.repr().data.offset(index as int)) @@ -1129,10 +1105,6 @@ impl<'a,T> ImmutableVector<'a, T> for &'a [T] { return None; } - fn map(&self, f: |t: &T| -> U) -> ~[U] { - self.iter().map(f).collect() - } - fn shift_ref(&mut self) -> Option<&'a T> { if self.len() == 0 { return None; } unsafe { @@ -3329,27 +3301,6 @@ mod tests { */ } - #[test] - fn test_map() { - // Test on-stack map. - let v = &[1u, 2u, 3u]; - let mut w = v.map(square_ref); - assert_eq!(w.len(), 3u); - assert_eq!(w[0], 1u); - assert_eq!(w[1], 4u); - assert_eq!(w[2], 9u); - - // Test on-heap map. - let v = ~[1u, 2u, 3u, 4u, 5u]; - w = v.map(square_ref); - assert_eq!(w.len(), 5u); - assert_eq!(w[0], 1u); - assert_eq!(w[1], 4u); - assert_eq!(w[2], 9u); - assert_eq!(w[3], 16u); - assert_eq!(w[4], 25u); - } - #[test] fn test_retain() { let mut v = ~[1, 2, 3, 4, 5]; @@ -3730,36 +3681,6 @@ mod tests { }) } - #[test] - #[should_fail] - fn test_map_fail() { - use rc::Rc; - let v = [(~0, Rc::new(0)), (~0, Rc::new(0)), (~0, Rc::new(0)), (~0, Rc::new(0))]; - let mut i = 0; - v.map(|_elt| { - if i == 2 { - fail!() - } - i += 1; - ~[(~0, Rc::new(0))] - }); - } - - #[test] - #[should_fail] - fn test_flat_map_fail() { - use rc::Rc; - let v = [(~0, Rc::new(0)), (~0, Rc::new(0)), (~0, Rc::new(0)), (~0, Rc::new(0))]; - let mut i = 0; - flat_map(v, |_elt| { - if i == 2 { - fail!() - } - i += 1; - ~[(~0, Rc::new(0))] - }); - } - #[test] #[should_fail] fn test_permute_fail() { diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index 4454801c129..11fd2b8ee22 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -902,13 +902,6 @@ impl Vec { } } - ///Apply a function to each element of a vector and return the results. - #[inline] - #[deprecated="Use `xs.iter().map(closure)` instead."] - pub fn map(&self, f: |t: &T| -> U) -> Vec { - self.iter().map(f).collect() - } - /// Takes ownership of the vector `other`, moving all elements into /// the current vector. This does not copy any elements, and it is /// illegal to use the `other` vector after calling this method -- cgit 1.4.1-3-g733a5