32
32
html_root_url = "http://doc.rust-lang.org/nightly/" ) ]
33
33
34
34
#![ feature( asm, macro_rules, phase, globs, slicing_syntax) ]
35
+ #![ feature( unboxed_closures) ]
35
36
36
37
extern crate getopts;
37
38
extern crate regex;
@@ -978,9 +979,11 @@ enum TestEvent {
978
979
979
980
pub type MonitorMsg = ( TestDesc , TestResult , Vec < u8 > ) ;
980
981
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
+ {
984
987
let filtered_tests = filter_tests ( opts, tests) ;
985
988
let filtered_descs = filtered_tests. iter ( )
986
989
. map ( |t| t. desc . clone ( ) )
@@ -1339,7 +1342,7 @@ pub fn black_box<T>(dummy: T) {
1339
1342
1340
1343
impl Bencher {
1341
1344
/// 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 {
1343
1346
self . dur = Duration :: span ( || {
1344
1347
let k = self . iterations ;
1345
1348
for _ in range ( 0u64 , k) {
@@ -1360,14 +1363,13 @@ impl Bencher {
1360
1363
}
1361
1364
}
1362
1365
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 ) {
1364
1367
self . iterations = n;
1365
1368
f ( self ) ;
1366
1369
}
1367
1370
1368
1371
// 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 ) {
1371
1373
// Initial bench run to get ballpark figure.
1372
1374
let mut n = 1_u64 ;
1373
1375
self . bench_n ( n, |x| f ( x) ) ;
@@ -1437,7 +1439,7 @@ pub mod bench {
1437
1439
use std:: time:: Duration ;
1438
1440
use super :: { Bencher , BenchSamples } ;
1439
1441
1440
- pub fn benchmark ( f: | & mut Bencher | ) -> BenchSamples {
1442
+ pub fn benchmark < F > ( f : F ) -> BenchSamples where F : FnMut ( & mut Bencher ) {
1441
1443
let mut bs = Bencher {
1442
1444
iterations : 0 ,
1443
1445
dur : Duration :: nanoseconds ( 0 ) ,
0 commit comments