我不明白错误cannot move out of borrowed content
。我已经收到了很多次,我一直都在解决它,但我从来不明白为什么。无法移出借用内容
例如:即使读一后
for current_char in line.clone().into_bytes().iter() {
我不明白的错误:
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
帖子如:
- Can't borrow File from &mut self (error msg: cannot move out of borrowed content)
- Changing a node in a tree in Rust
什么是这种错误的由来?
你看着[类似这样的问题(http://stackoverflow.com/q/28034646/1256624)? (顺便说一下,字符串提供'.bytes()'方法)。 – huon 2015-01-26 21:13:05
是的,我看着它,但不明白:(而且我的字符串是一个std :: string :: String,根据文档,没有.bytes()方法 – Peekmo 2015-01-26 21:15:48
它被称为'.as_bytes()' – bluss 2015-01-26 21:37:58