trpl-zh-cn/listings/ch08-common-collections/listing-08-04/src/main.rs

15 lines
353 B
Rust
Raw Normal View History

2022-02-06 16:43:51 +08:00
fn main() {
// ANCHOR: here
2023-01-16 17:34:52 +08:00
let v = vec![1, 2, 3, 4, 5];
2022-02-06 16:43:51 +08:00
2023-01-16 17:34:52 +08:00
let third: &i32 = &v[2];
println!("The third element is {third}");
let third: Option<&i32> = v.get(2);
match third {
Some(third) => println!("The third element is {third}"),
None => println!("There is no third element."),
}
// ANCHOR_END: here
2022-02-06 16:43:51 +08:00
}