rsm: Simplify serialisation.

This commit is contained in:
Emmanuel Gil Peyrot 2017-10-31 22:21:50 +00:00
commit 7950fe8f52

View file

@ -88,34 +88,22 @@ impl TryFrom<Element> for Set {
impl From<Set> for Element { impl From<Set> for Element {
fn from(set: Set) -> Element { fn from(set: Set) -> Element {
let mut elem = Element::builder("set") let first = set.first.clone()
.ns(ns::RSM) .map(|first| Element::builder("first")
.build();
if set.after.is_some() {
elem.append_child(Element::builder("after").ns(ns::RSM).append(set.after).build());
}
if set.before.is_some() {
elem.append_child(Element::builder("before").ns(ns::RSM).append(set.before).build());
}
if let Some(count) = set.count {
elem.append_child(Element::builder("count").ns(ns::RSM).append(format!("{}", count)).build());
}
if set.first.is_some() {
elem.append_child(Element::builder("first")
.ns(ns::RSM) .ns(ns::RSM)
.attr("index", set.first_index) .attr("index", set.first_index)
.append(set.first).build()); .append(first)
} .build());
if let Some(index) = set.index { Element::builder("set")
elem.append_child(Element::builder("index").ns(ns::RSM).append(format!("{}", index)).build()); .ns(ns::RSM)
} .append(set.after.map(|after| Element::builder("after").ns(ns::RSM).append(after).build()))
if set.last.is_some() { .append(set.before.map(|before| Element::builder("before").ns(ns::RSM).append(before).build()))
elem.append_child(Element::builder("last").ns(ns::RSM).append(set.last).build()); .append(set.count.map(|count| Element::builder("count").ns(ns::RSM).append(format!("{}", count)).build()))
} .append(first)
if let Some(max) = set.max { .append(set.index.map(|index| Element::builder("index").ns(ns::RSM).append(format!("{}", index)).build()))
elem.append_child(Element::builder("max").ns(ns::RSM).append(format!("{}", max)).build()); .append(set.last.map(|last| Element::builder("last").ns(ns::RSM).append(last).build()))
} .append(set.max.map(|max| Element::builder("max").ns(ns::RSM).append(format!("{}", max)).build()))
elem .build()
} }
} }