小编Fel*_* AA的帖子

向量 pop() 返回选项

我是 Rust 的初学者。我看到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]);

Run Code Online (Sandbox Code Playgroud)
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]);
   |  
Run Code Online (Sandbox Code Playgroud)

types rust vec

0
推荐指数
1
解决办法
334
查看次数

标签 统计

rust ×1

types ×1

vec ×1