【发布时间】:2019-12-31 05:43:11
【问题描述】:
现在我正在编写一个程序,其中我正在使用基于 for 循环中的条件构造的字符串来更新 Vec。我正在尝试做的一个(非常做作的)简化形式如下:
fn main() {
let mut arr = vec!["_"; 5];
for (i, chr) in "abcde".char_indices() {
arr[i] = &chr.to_string().repeat(3);
}
}
但是,我收到了错误 temporary value dropped while borrowed。关于在这里做什么的任何指示?
【问题讨论】: