2018-08-30 07:18:55 -05:00
|
|
|
// run-pass
|
2014-12-28 15:45:56 -06:00
|
|
|
use std::ops::FnMut;
|
|
|
|
|
2015-03-25 19:06:52 -05:00
|
|
|
fn make_adder(x: isize) -> Box<FnMut(isize)->isize + 'static> {
|
2015-02-15 02:52:21 -06:00
|
|
|
Box::new(move |y| { x + y })
|
2014-12-28 15:45:56 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn main() {
|
|
|
|
let mut adder = make_adder(3);
|
|
|
|
let z = (*adder)(2);
|
|
|
|
println!("{}", z);
|
|
|
|
assert_eq!(z, 5);
|
|
|
|
}
|