Function sauron::prelude::prelude::html::attributes::maybe_attr
source · pub fn maybe_attr<MSG>(
name: &'static str,
value: Option<impl Into<Value>>
) -> Attribute<MSG>
Expand description
Set the attribute of this element if value is Some, empty attribute otherwise
§Examples
use sauron::{*, html::attributes::maybe_attr};
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());