mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
16 lines
308 B
Rust
16 lines
308 B
Rust
// run-pass
|
|
|
|
use std::ops::FnMut;
|
|
|
|
fn make_adder(x: i32) -> Box<dyn FnMut(i32)->i32+'static> {
|
|
Box::new(move |y: i32| -> i32 { x + y }) as
|
|
Box<dyn FnMut(i32)->i32+'static>
|
|
}
|
|
|
|
pub fn main() {
|
|
let mut adder = make_adder(3);
|
|
let z = adder(2);
|
|
println!("{}", z);
|
|
assert_eq!(z, 5);
|
|
}
|