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

pub fn closure_math<F: Fn() -> i32>(op: F) -> i32

闭包: 作为参数

Basic usage:

pub fn math<F: Fn() -> i32>(op: F) -> i32 {
    op()
}
let a = 2;
let b = 3;
assert_eq!(math(|| a + b), 5);
assert_eq!(math(|| a * b), 6);Run