頭條地址:https://www.ixigua.com/i676544267458235648...
B站地址:https://www.bilibili.com/video/av78062009?...
網易雲課堂地址:https://study.163.com/course/introduction....
例子:
let some_value = Some(10);
match some_value {
Some(3) => println!("three"),
_ => println! (“other”),
}
但是,當我們只關心等於3時的情況,用match就感覺程式碼太多了,那麼我們就可以使用if let:
if let Some(3) = some_u8_value {
println!("three");
} else {
println! (“other”);
}