主页 > 经验 >

学习Rust编程——Option

2023-09-16 13:23     编辑:xiaofeng    点击: A+

专题:
【导读】
// using_options_match.rsuse std::collections::HashMap;fn main() { le
// using_options_match.rsuse std::collections::HashMap;fn main() { let mut map = HashMap::new(); map.insert("one", 1); map.insert("two", 2); let incremented_value = match map.get("one") { Some(val) => val + 1, None => 0 }; println!("{}", incremented_value);}// using_options_unwrap.rsuse std::collections::HashMap;fn main() { let mut map = HashMap::new(); map.insert("one", 1); map.insert("two", 2); let incremented_value = map.get("three").unwrap() + 1; println!("{}", incremented_value);}
我要投稿

分享到:

相关文章