I want to use xml::reader::EventReader
from xml_rs
.
I need both the parsed events and their position in the XML file:
use xml::common::{Position, TextPosition};
use xml::reader::{EventReader};
fn main() {
let s = "<?xml version=\"1.0\"\nencoding=\"UTF-8\"?>\n<ooo></ooo>\n";
let xml = EventReader::new(s.as_bytes());
for e in xml {
println!("event: {:?}", e);
println!("pos: {:?}", xml.position());
}
}
But the compiler complains:
error[E0382]: borrow of moved value: `xml`
--> src/main.rs:9:31
|
6 | let xml = EventReader::new(s.as_bytes());
| --- move occurs because `xml` has type `xml::reader::EventReader<&[u8]>`, which does not implement the `Copy` trait
7 | for e in xml {
| ---
| |
| value moved here
| help: consider borrowing to avoid moving into the for loop: `&xml`
8 | println!("event: {:?}", e);
9 | println!("pos: {:?}", xml.position());
| ^^^ value borrowed here after move
Without the second println!
the code works.
[package]
name = "xmlproblem"
version = "0.1.0"
edition = "2018"
[dependencies]
xml-rs = "0.8"
How do I solve this?