在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
fn add_one_v1 (x: u32) -> u32 { x + 1 } let add_one_v2 = |x: u32| -> u32 { x + 1 }; let add_one_v3 = |x| { x + 1 }; let add_one_v4 = |x| x + 1 ;
pub fn test3() { let example_closure = |x| x; let s = example_closure(String::from("hello")); let n = example_closure(5); }
--> src/base/k_closure.rs:53:29 | 53 | let n = example_closure(5); | ^ | | | expected struct `String`, found integer | help: try using a conversion method: `5.to_string()` The first time we call
不换数据类型,下面的是正确的 pub fn test3() { let example_closure = |x| x; let s = example_closure(6); println!("{}",s); let n = example_closure(5); println!("{}",n); }
6 5
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论