From d5c332688c83043dffcf14ef8fd6ba3fafdae55e Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Fri, 5 Dec 2014 16:54:09 -0500 Subject: [PATCH] libcollections: use unboxed closures in `Vec` methods --- src/libcollections/vec.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index f8a971db173..2ed8686394c 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -206,7 +206,7 @@ impl Vec { #[inline] #[unstable = "the naming is uncertain as well as this migrating to unboxed \ closures in the future"] - pub fn from_fn(length: uint, op: |uint| -> T) -> Vec { + pub fn from_fn(length: uint, mut op: F) -> Vec where F: FnMut(uint) -> T { unsafe { let mut xs = Vec::with_capacity(length); while xs.len < length { @@ -289,7 +289,7 @@ impl Vec { /// ``` #[inline] #[experimental] - pub fn partition(self, f: |&T| -> bool) -> (Vec, Vec) { + pub fn partition(self, mut f: F) -> (Vec, Vec) where F: FnMut(&T) -> bool { let mut lefts = Vec::new(); let mut rights = Vec::new(); @@ -400,7 +400,7 @@ impl Vec { /// assert_eq!(odd, vec![1i, 3]); /// ``` #[experimental] - pub fn partitioned(&self, f: |&T| -> bool) -> (Vec, Vec) { + pub fn partitioned(&self, mut f: F) -> (Vec, Vec) where F: FnMut(&T) -> bool { let mut lefts = Vec::new(); let mut rights = Vec::new(); @@ -991,7 +991,7 @@ impl Vec { /// assert_eq!(vec, vec![2, 4]); /// ``` #[unstable = "the closure argument may become an unboxed closure"] - pub fn retain(&mut self, f: |&T| -> bool) { + pub fn retain(&mut self, mut f: F) where F: FnMut(&T) -> bool { let len = self.len(); let mut del = 0u; { @@ -1023,7 +1023,7 @@ impl Vec { /// assert_eq!(vec, vec![0, 1, 0, 1, 2]); /// ``` #[unstable = "this function may be renamed or change to unboxed closures"] - pub fn grow_fn(&mut self, n: uint, f: |uint| -> T) { + pub fn grow_fn(&mut self, n: uint, mut f: F) where F: FnMut(uint) -> T { self.reserve(n); for i in range(0u, n) { self.push(f(i)); @@ -1570,7 +1570,7 @@ impl Vec { /// let newtyped_bytes = bytes.map_in_place(|x| Newtype(x)); /// assert_eq!(newtyped_bytes.as_slice(), [Newtype(0x11), Newtype(0x22)].as_slice()); /// ``` - pub fn map_in_place(self, f: |T| -> U) -> Vec { + pub fn map_in_place(self, mut f: F) -> Vec where F: FnMut(T) -> U { // FIXME: Assert statically that the types `T` and `U` have the same // size. assert!(mem::size_of::() == mem::size_of::());