[][src]Function tao_of_rust::ch02::function::two_times_dyn

pub fn two_times_dyn() -> Box<dyn Fn(i32) -> i32>

闭包: 作为返回值(动态分发)Rust 2018

Basic usage:

fn two_times_dyn() -> Box<dyn Fn(i32) -> i32> {
    let i = 2;
    Box::new(move |j| j * i)
}
let result = two_times_dyn();
assert_eq!(result(2), 4);Run