Skip to content

Commit d5c3326

Browse files
author
Jorge Aparicio
committed
libcollections: use unboxed closures in Vec methods
1 parent 0055678 commit d5c3326

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/libcollections/vec.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ impl<T> Vec<T> {
206206
#[inline]
207207
#[unstable = "the naming is uncertain as well as this migrating to unboxed \
208208
closures in the future"]
209-
pub fn from_fn(length: uint, op: |uint| -> T) -> Vec<T> {
209+
pub fn from_fn<F>(length: uint, mut op: F) -> Vec<T> where F: FnMut(uint) -> T {
210210
unsafe {
211211
let mut xs = Vec::with_capacity(length);
212212
while xs.len < length {
@@ -289,7 +289,7 @@ impl<T> Vec<T> {
289289
/// ```
290290
#[inline]
291291
#[experimental]
292-
pub fn partition(self, f: |&T| -> bool) -> (Vec<T>, Vec<T>) {
292+
pub fn partition<F>(self, mut f: F) -> (Vec<T>, Vec<T>) where F: FnMut(&T) -> bool {
293293
let mut lefts = Vec::new();
294294
let mut rights = Vec::new();
295295

@@ -400,7 +400,7 @@ impl<T: Clone> Vec<T> {
400400
/// assert_eq!(odd, vec![1i, 3]);
401401
/// ```
402402
#[experimental]
403-
pub fn partitioned(&self, f: |&T| -> bool) -> (Vec<T>, Vec<T>) {
403+
pub fn partitioned<F>(&self, mut f: F) -> (Vec<T>, Vec<T>) where F: FnMut(&T) -> bool {
404404
let mut lefts = Vec::new();
405405
let mut rights = Vec::new();
406406

@@ -991,7 +991,7 @@ impl<T> Vec<T> {
991991
/// assert_eq!(vec, vec![2, 4]);
992992
/// ```
993993
#[unstable = "the closure argument may become an unboxed closure"]
994-
pub fn retain(&mut self, f: |&T| -> bool) {
994+
pub fn retain<F>(&mut self, mut f: F) where F: FnMut(&T) -> bool {
995995
let len = self.len();
996996
let mut del = 0u;
997997
{
@@ -1023,7 +1023,7 @@ impl<T> Vec<T> {
10231023
/// assert_eq!(vec, vec![0, 1, 0, 1, 2]);
10241024
/// ```
10251025
#[unstable = "this function may be renamed or change to unboxed closures"]
1026-
pub fn grow_fn(&mut self, n: uint, f: |uint| -> T) {
1026+
pub fn grow_fn<F>(&mut self, n: uint, mut f: F) where F: FnMut(uint) -> T {
10271027
self.reserve(n);
10281028
for i in range(0u, n) {
10291029
self.push(f(i));
@@ -1570,7 +1570,7 @@ impl<T> Vec<T> {
15701570
/// let newtyped_bytes = bytes.map_in_place(|x| Newtype(x));
15711571
/// assert_eq!(newtyped_bytes.as_slice(), [Newtype(0x11), Newtype(0x22)].as_slice());
15721572
/// ```
1573-
pub fn map_in_place<U>(self, f: |T| -> U) -> Vec<U> {
1573+
pub fn map_in_place<U, F>(self, mut f: F) -> Vec<U> where F: FnMut(T) -> U {
15741574
// FIXME: Assert statically that the types `T` and `U` have the same
15751575
// size.
15761576
assert!(mem::size_of::<T>() == mem::size_of::<U>());

0 commit comments

Comments
 (0)