Created
October 14, 2015 19:55
-
-
Save xitep/de8bcf7477aa1e3a6e06 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
why does the for-loop consume `evts`: | |
fn next_start_elem<R: Read>(evts: &mut Events<R>) -> Result<String, Error> { | |
for evt in evts { | |
if let XmlEvent::StartElement{ name, .. } = try!(evt) { | |
return Ok(name.local_name); | |
} | |
} | |
let _ = evts.text_position(); | |
Err(Error::UnexpectedEof) | |
} | |
error: | |
parser.rs:52:13: 52:17 error: use of moved value: `*evts` [E0382] | |
parser.rs:52 let _ = evts.text_position(); | |
^~~~ | |
parser.rs:52:13: 52:17 help: run `rustc --explain E0382` to see a detailed explanation | |
parser.rs:47:16: 47:20 note: `evts` moved here because it has type `&mut xml::reader::Events<R>`, which is non-copyable | |
parser.rs:47 for evt in evts { | |
^~~~ | |
while this is ok: | |
fn next_start_elem<R: Read>(evts: &mut Events<R>) -> Result<String, Error> { | |
loop { | |
match evts.next() { | |
Some(evt) => { | |
if let XmlEvent::StartElement{ name, .. } = try!(evt) { | |
return Ok(name.local_name); | |
} | |
} | |
None => break, | |
} | |
} | |
let _ = evts.text_position(); | |
Err(Error::UnexpectedEof) | |
} | |
Events implements Iterator as: | |
impl<R: Read> Iterator for Events<R> { | |
type Item = Result<XmlEvent>; | |
#[inline] | |
fn next(&mut self) -> Option<Result<XmlEvent>> { | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment