我在Rust Rust中有一个固定大小的数组,我想将它变成(String, String)
。我可以在不复制值的情况下执行此操作吗将数组移动到元组
的一块,我在特别工作代码如下:
let (basis, names_0, names_1) = if let Some(names) = self.arg_name {
(ComparisonBasis::Name, names[0], names[1])
} else {
(ComparisonBasis::File, self.arg_file[0], self.arg_file[1])
};
类型:
self.arg_name: Option<[String; 2]>
self.arg_file: Vec<String>
现在,我得到错误
cannot move out of type `[std::string::String; 2]`, a non-copy fixed-size array [E0508]
和
cannot move out of indexed content [E0507]
if
最后,我想我有点过分热衷于尝试优化克隆的调用。这个问题中的一段代码每次程序运行只调用一次,它只有两个(可能很小)的字符串。 – Apanatshka