Option型は値がない可能性を示す。
fn main() { let mut values: Vec<Option<i32>> = Vec::new(); values.push(Some(777)); values.push(None); for value in values { match value { Some(_) => println!("It's threre, {}", value.unwrap()), None => println!("No value, it's None"), } } }
Compiling app v0.1.0 (/home/vagrant/dev/rust/app)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.25s
Running `target/debug/app`
It’s threre, 777
No value, it’s None
Option型を使う場合は、Some、Noneもセットで使うのね。
なるほど〜、結構基本的なところだな〜