From 745225d905a691c700c8a62b08a7262ed0d1edc5 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Tue, 9 Dec 2014 17:00:29 -0500 Subject: libtest: use unboxed closures --- src/libtest/lib.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'src/libtest') diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index ffc26738dd7..7436a8af307 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -32,6 +32,7 @@ html_root_url = "http://doc.rust-lang.org/nightly/")] #![feature(asm, macro_rules, phase, globs, slicing_syntax)] +#![feature(unboxed_closures)] extern crate getopts; extern crate regex; @@ -978,9 +979,11 @@ enum TestEvent { pub type MonitorMsg = (TestDesc, TestResult, Vec ); -fn run_tests(opts: &TestOpts, - tests: Vec , - callback: |e: TestEvent| -> io::IoResult<()>) -> io::IoResult<()> { +fn run_tests(opts: &TestOpts, + tests: Vec , + mut callback: F) -> io::IoResult<()> where + F: FnMut(TestEvent) -> io::IoResult<()>, +{ let filtered_tests = filter_tests(opts, tests); let filtered_descs = filtered_tests.iter() .map(|t| t.desc.clone()) @@ -1339,7 +1342,7 @@ pub fn black_box(dummy: T) { impl Bencher { /// Callback for benchmark functions to run in their body. - pub fn iter(&mut self, inner: || -> T) { + pub fn iter(&mut self, mut inner: F) where F: FnMut() -> T { self.dur = Duration::span(|| { let k = self.iterations; for _ in range(0u64, k) { @@ -1360,14 +1363,13 @@ impl Bencher { } } - pub fn bench_n(&mut self, n: u64, f: |&mut Bencher|) { + pub fn bench_n(&mut self, n: u64, f: F) where F: FnOnce(&mut Bencher) { self.iterations = n; f(self); } // This is a more statistics-driven benchmark algorithm - pub fn auto_bench(&mut self, f: |&mut Bencher|) -> stats::Summary { - + pub fn auto_bench(&mut self, mut f: F) -> stats::Summary where F: FnMut(&mut Bencher) { // Initial bench run to get ballpark figure. let mut n = 1_u64; self.bench_n(n, |x| f(x)); @@ -1437,7 +1439,7 @@ pub mod bench { use std::time::Duration; use super::{Bencher, BenchSamples}; - pub fn benchmark(f: |&mut Bencher|) -> BenchSamples { + pub fn benchmark(f: F) -> BenchSamples where F: FnMut(&mut Bencher) { let mut bs = Bencher { iterations: 0, dur: Duration::nanoseconds(0), -- cgit 1.4.1-3-g733a5