pub fn from_reader<T: FromXml, R: BufRead>(r: R) -> Result<T>
Available on crate feature
std
only.Expand description
§Parse a value from a io::BufRead
This function parses the XML found in r
, assuming it contains a
complete XML document (with optional XML declaration) and builds a T
from it (without buffering the tree in memory).
If conversion fails, a Error
is returned. In
particular, if T
expects a different element header than the element
header at the root of the document in r
,
Error::TypeMismatch
is returned.
§Example
#[derive(FromXml, PartialEq, Debug)]
#[xml(namespace = "urn:example", name = "foo")]
struct Foo {
#[xml(attribute)]
a: String,
}
// let file = ..
assert_eq!(
Foo { a: "some-value".to_owned() },
from_reader(BufReader::new(file)).unwrap(),
);