Skip to content

Commit 745225d

Browse files
author
Jorge Aparicio
committed
libtest: use unboxed closures
1 parent 015c0fc commit 745225d

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/libtest/lib.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
html_root_url = "http://doc.rust-lang.org/nightly/")]
3333

3434
#![feature(asm, macro_rules, phase, globs, slicing_syntax)]
35+
#![feature(unboxed_closures)]
3536

3637
extern crate getopts;
3738
extern crate regex;
@@ -978,9 +979,11 @@ enum TestEvent {
978979

979980
pub type MonitorMsg = (TestDesc, TestResult, Vec<u8> );
980981

981-
fn run_tests(opts: &TestOpts,
982-
tests: Vec<TestDescAndFn> ,
983-
callback: |e: TestEvent| -> io::IoResult<()>) -> io::IoResult<()> {
982+
fn run_tests<F>(opts: &TestOpts,
983+
tests: Vec<TestDescAndFn> ,
984+
mut callback: F) -> io::IoResult<()> where
985+
F: FnMut(TestEvent) -> io::IoResult<()>,
986+
{
984987
let filtered_tests = filter_tests(opts, tests);
985988
let filtered_descs = filtered_tests.iter()
986989
.map(|t| t.desc.clone())
@@ -1339,7 +1342,7 @@ pub fn black_box<T>(dummy: T) {
13391342

13401343
impl Bencher {
13411344
/// Callback for benchmark functions to run in their body.
1342-
pub fn iter<T>(&mut self, inner: || -> T) {
1345+
pub fn iter<T, F>(&mut self, mut inner: F) where F: FnMut() -> T {
13431346
self.dur = Duration::span(|| {
13441347
let k = self.iterations;
13451348
for _ in range(0u64, k) {
@@ -1360,14 +1363,13 @@ impl Bencher {
13601363
}
13611364
}
13621365

1363-
pub fn bench_n(&mut self, n: u64, f: |&mut Bencher|) {
1366+
pub fn bench_n<F>(&mut self, n: u64, f: F) where F: FnOnce(&mut Bencher) {
13641367
self.iterations = n;
13651368
f(self);
13661369
}
13671370

13681371
// This is a more statistics-driven benchmark algorithm
1369-
pub fn auto_bench(&mut self, f: |&mut Bencher|) -> stats::Summary<f64> {
1370-
1372+
pub fn auto_bench<F>(&mut self, mut f: F) -> stats::Summary<f64> where F: FnMut(&mut Bencher) {
13711373
// Initial bench run to get ballpark figure.
13721374
let mut n = 1_u64;
13731375
self.bench_n(n, |x| f(x));
@@ -1437,7 +1439,7 @@ pub mod bench {
14371439
use std::time::Duration;
14381440
use super::{Bencher, BenchSamples};
14391441

1440-
pub fn benchmark(f: |&mut Bencher|) -> BenchSamples {
1442+
pub fn benchmark<F>(f: F) -> BenchSamples where F: FnMut(&mut Bencher) {
14411443
let mut bs = Bencher {
14421444
iterations: 0,
14431445
dur: Duration::nanoseconds(0),

0 commit comments

Comments
 (0)