我是生锈的初学者。我看到pop()
向量返回<Option>
类型的方法。pop()
获得变量价值的正确方法是什么?
let mut queue: Vec<[usize; 2]> = Vec::new();
queue.push([1, 2]);
queue.push([3, 4]);
let coords = queue.pop();
println!("{}, {}", coords[0], coords[1]);
error[E0608]: cannot index into a value of type `std::option::Option<[usize; 2]>`
--> src/main.rs:99:24
|
99 | println!("{}, {}", coords[0], coords[1]);
|