mirror of
https://github.com/KaiserY/trpl-zh-cn
synced 2025-05-07 14:30:19 +08:00
15 lines
353 B
Rust
15 lines
353 B
Rust
fn main() {
|
|
// ANCHOR: here
|
|
let v = vec![1, 2, 3, 4, 5];
|
|
|
|
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
|
|
}
|