Function sauron::prelude::maybe_attr [−][src]
pub fn maybe_attr<V, MSG>(
name: &'static str,
value: Option<V>
) -> Attribute<&'static str, &'static str, AttributeValue<MSG>> where
V: Into<Value>,
Expand description
Set the attribute of this element if value is Some, empty attribute otherwise
Examples
use sauron::prelude::*;
let width = Some(10);
let html: Node<()> = button(vec![maybe_attr("width", width)], vec![]);
let expected = r#"<button width="10"></button>"#;
assert_eq!(expected, html.render_to_string());
let width = None::<usize>;
let html: Node<()> = button(vec![maybe_attr("width", width)], vec![]);
let expected = r#"<button></button>"#;
assert_eq!(expected, html.render_to_string());