Skip to main content

Value

Trait Value 

Source
pub trait Value: Sealed { }
Expand description

Types that can be used as attribute values in the html! macro.

ValueRenders the attribute?
T
true
false
Some<T>
None

where T: Render

§Examples

Passing a bool conditionally renders a boolean attribute.

let checked = true;

let markup = html! {
    input r#type: "checkbox" checked: (checked);
};

assert_eq!(markup.render().0, r#"<input type="checkbox" checked>"#);

To conditionally include an attribute with a value, pass an Option<T>. The attribute is only rendered when the value is Some.

let cooldown = Some("200ms");

let markup = html! {
    button data_cooldown: (cooldown) {
        "click me"
    }
};

assert_eq!(markup.render().0, r#"<button data-cooldown="200ms">click me</button>"#);

Implementations on Foreign Types§

Source§

impl Value for bool

Source§

impl<R: Render> Value for Option<R>

Implementors§

Source§

impl<R: Render> Value for R