mirror of
https://gitlab.com/xmpp-rs/xmpp-rs.git
synced 2024-07-12 22:21:53 +00:00
ecaps2: Simplify parsing.
This commit is contained in:
parent
47c9263b86
commit
82fcf3bad5
1 changed files with 5 additions and 13 deletions
|
@ -30,17 +30,11 @@ impl TryFrom<Element> for ECaps2 {
|
||||||
type Err = Error;
|
type Err = Error;
|
||||||
|
|
||||||
fn try_from(elem: Element) -> Result<ECaps2, Error> {
|
fn try_from(elem: Element) -> Result<ECaps2, Error> {
|
||||||
if !elem.is("c", ns::ECAPS2) {
|
check_self!(elem, "c", ns::ECAPS2, "ecaps2");
|
||||||
return Err(Error::ParseError("This is not an ecaps2 element."));
|
check_no_attributes!(elem, "ecaps2");
|
||||||
}
|
|
||||||
let mut hashes = vec!();
|
let mut hashes = vec!();
|
||||||
for child in elem.children() {
|
for child in elem.children() {
|
||||||
if child.is("hash", ns::HASHES) {
|
hashes.push(Hash::try_from(child.clone())?);
|
||||||
let hash = Hash::try_from(child.clone())?;
|
|
||||||
hashes.push(hash);
|
|
||||||
} else {
|
|
||||||
return Err(Error::ParseError("Unknown child in ecaps2 element."));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Ok(ECaps2 {
|
Ok(ECaps2 {
|
||||||
hashes: hashes,
|
hashes: hashes,
|
||||||
|
@ -52,9 +46,7 @@ impl From<ECaps2> for Element {
|
||||||
fn from(ecaps2: ECaps2) -> Element {
|
fn from(ecaps2: ECaps2) -> Element {
|
||||||
Element::builder("c")
|
Element::builder("c")
|
||||||
.ns(ns::ECAPS2)
|
.ns(ns::ECAPS2)
|
||||||
.append(ecaps2.hashes.into_iter()
|
.append(ecaps2.hashes)
|
||||||
.map(Element::from)
|
|
||||||
.collect::<Vec<_>>())
|
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -207,7 +199,7 @@ mod tests {
|
||||||
Error::ParseError(string) => string,
|
Error::ParseError(string) => string,
|
||||||
_ => panic!(),
|
_ => panic!(),
|
||||||
};
|
};
|
||||||
assert_eq!(message, "Unknown child in ecaps2 element.");
|
assert_eq!(message, "This is not a hash element.");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Reference in a new issue