返回位置的 impl Trait

版本新特性 / Rust 1.26

// *** before: ***
// the exact type of a closure cannot be named, so it went into a box,
// which costs a pointer and a call through a table
fn adder(n: i32) -> Box<dyn Fn(i32) -> i32> {
    Box::new(move |x| x + n)
}

// *** in version 1.26: ***
// the real type stays, and no box is needed
fn adder(n: i32) -> impl Fn(i32) -> i32 {
    move |x| x + n
}