无法摆脱借来的内容

无法摆脱借来的内容

我不明白这个错误cannot move out of borrowed content。我收到了很多次,我总是解决它,但我从来没有理解为什么。

例如:

for line in self.xslg_file.iter() {
    self.buffer.clear();

    for current_char in line.into_bytes().iter() {
        self.buffer.push(*current_char as char);
    }

    println!("{}", line);}

产生错误:

error[E0507]: cannot move out of borrowed content
  --> src/main.rs:31:33
   |
31 |             for current_char in line.into_bytes().iter() {
   |                                 ^^^^ cannot move out of borrowed content

我通过克隆解决了这个问题line

for current_char in line.clone().into_bytes().iter() {

即使在阅读其他帖子后我也不明白错误:

这种错误的起源是什么?


慕神8447489
浏览 382回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

SQL Server