Accumulator factory: Difference between revisions

m
Modfiy rust solution to use impl Trait instead of Box<dyn Trait>
(Added Wren)
m (Modfiy rust solution to use impl Trait instead of Box<dyn Trait>)
Line 2,843:
Changing "x = foo(1.)" to "x = foo(1)" in the code below should not change the output (it does).
 
<lang rust>// rustc -V1.26.0 or later
// rustc 1.2.0-nightly (0cc99f9cc 2015-05-17) (built 2015-05-18)
 
use std::ops::Add;
 
fn foo<Num>(n: Num) -> Box<impl FnMut(Num) -> Num>
where Num: Add<Output=Num> + Copy + 'static {
let mut acc = n;
Box::new(move |i: Num| {
acc = acc + i;
acc
})
}
 
Anonymous user