如何在 Rust 中创建一个大小在运行时定义的数组?
基本上,您如何在 Rust 中转换以下代码:
void f(int n){ return std::vector<int>(n); }
?
这在 rust 中是不可能的:
let n = 15;
let board: [int, ..n];
注意:我看到不可能以简单的方式做到这一点,here , 但我拒绝接受这么简单的事情是不可能的:p
非常感谢!
最佳答案
没关系,我是这样找到的:
let n = 15; // number of items
let val = 17; // value to replicate
let v = std::vec::from_elem(val, n);
关于vector - Rust - 大小在运行时定义的向量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21393508/