20 lines
384 B
Text
20 lines
384 B
Text
// rustc -V
|
|
// rustc 1.2.0-nightly (0cc99f9cc 2015-05-17) (built 2015-05-18)
|
|
|
|
use std::ops::Add;
|
|
|
|
fn foo<Num>(n: Num) -> Box<FnMut(Num) -> Num>
|
|
where Num: Add<Output=Num> + Copy + 'static {
|
|
let mut acc = n;
|
|
Box::new(move |i: Num| {
|
|
acc = acc + i;
|
|
acc
|
|
})
|
|
}
|
|
|
|
fn main() {
|
|
let mut x = foo(1.);
|
|
x(5.);
|
|
foo(3.);
|
|
println!("{}", x(2.3));
|
|
}
|