【发布时间】:2016-11-12 10:43:57
【问题描述】:
我有一个固定大小的数组Strings:[String; 2]。我想把它变成(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的两条手臂
【问题讨论】:
-
最后,我想我尝试优化克隆调用有点过分了。每次程序运行时,问题中的代码只被调用一次,它只是两个(可能很小)字符串。