2018-08-30 14:18:55 +02:00
|
|
|
// run-pass
|
2014-05-28 22:26:56 -07:00
|
|
|
|
|
|
|
use std::ops::FnMut;
|
|
|
|
|
2019-05-28 14:47:21 -04:00
|
|
|
fn make_adder(x: i32) -> Box<dyn FnMut(i32)->i32+'static> {
|
2021-08-25 02:39:40 +02:00
|
|
|
Box::new(move |y: i32| -> i32 { x + y }) as
|
2019-05-28 14:47:21 -04:00
|
|
|
Box<dyn FnMut(i32)->i32+'static>
|
2014-05-28 22:26:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn main() {
|
|
|
|
let mut adder = make_adder(3);
|
2015-01-05 14:07:10 -05:00
|
|
|
let z = adder(2);
|
2014-05-28 22:26:56 -07:00
|
|
|
println!("{}", z);
|
|
|
|
assert_eq!(z, 5);
|
|
|
|
}
|