Function sauron_core::html::attributes::maybe_attr [−][src]
pub fn maybe_attr<V, MSG>(
name: AttributeName,
value: Option<V>
) -> Attribute<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());