Skip to content

Commit 6f19f8d

Browse files
author
Jorge Aparicio
committed
libcollections: use unboxed closures in DList methods
1 parent d5c3326 commit 6f19f8d

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

src/libcollections/dlist.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -351,18 +351,16 @@ impl<T> DList<T> {
351351
/// println!("{}", e); // prints 2, then 4, then 11, then 7, then 8
352352
/// }
353353
/// ```
354-
pub fn insert_when(&mut self, elt: T, f: |&T, &T| -> bool) {
355-
{
356-
let mut it = self.iter_mut();
357-
loop {
358-
match it.peek_next() {
359-
None => break,
360-
Some(x) => if f(x, &elt) { break }
361-
}
362-
it.next();
354+
pub fn insert_when<F>(&mut self, elt: T, mut f: F) where F: FnMut(&T, &T) -> bool {
355+
let mut it = self.iter_mut();
356+
loop {
357+
match it.peek_next() {
358+
None => break,
359+
Some(x) => if f(x, &elt) { break }
363360
}
364-
it.insert_next(elt);
361+
it.next();
365362
}
363+
it.insert_next(elt);
366364
}
367365

368366
/// Merges `other` into this `DList`, using the function `f`.
@@ -371,7 +369,7 @@ impl<T> DList<T> {
371369
/// put `a` in the result if `f(a, b)` is true, and otherwise `b`.
372370
///
373371
/// This operation should compute in O(max(N, M)) time.
374-
pub fn merge(&mut self, mut other: DList<T>, f: |&T, &T| -> bool) {
372+
pub fn merge<F>(&mut self, mut other: DList<T>, mut f: F) where F: FnMut(&T, &T) -> bool {
375373
{
376374
let mut it = self.iter_mut();
377375
loop {

0 commit comments

Comments
 (0)