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