From 4fb909cfd1e5d77278132b76d1bff62ed34afe07 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Tue, 31 Oct 2017 23:33:34 +0000 Subject: [PATCH] data_forms: Simplify serialisation using .map(). --- src/data_forms.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/data_forms.rs b/src/data_forms.rs index a54be9c2..9b173b8a 100644 --- a/src/data_forms.rs +++ b/src/data_forms.rs @@ -218,8 +218,8 @@ impl From for Element { Element::builder("x") .ns(ns::DATA_FORMS) .attr("type", form.type_) - .append(if form.title.is_some() { Some(Element::builder("title").ns(ns::DATA_FORMS).append(form.title)) } else { None }) - .append(if form.instructions.is_some() { Some(Element::builder("instructions").ns(ns::DATA_FORMS).append(form.instructions)) } else { None }) + .append(form.title.map(|title| Element::builder("title").ns(ns::DATA_FORMS).append(title))) + .append(form.instructions.map(|text| Element::builder("instructions").ns(ns::DATA_FORMS).append(text))) .append(form.fields) .build() }