Skip to content

Display is not implemented for StringAttribute #778

Description

@tguichaoua

In the Attribute Passthrough chapter of the book, in the last code block we have

use sycamore::web::StringAttribute;

#[component(inline_props)]
fn Button(
    #[prop(attributes(html, button))]
    attributes: Attributes,
    // StringAttribute is a type alias for MaybeDyn containing a string.
    class: StringAttribute,
) -> View {
    // We still want the attribute to be reactive.
    let class = move || format!("{class} custom-button");
    view! {
        button(class=class, ..attributes)
    }
}

But StringAttribute is a type alias for MaybeDyn<Option<Cow<'static, str>>> which didn't implement Display.

One possible solution will be to turn StringAttribute into a new type around MaybeDyn<Option<Cow<'static, str>>> (with Deref and DerefMut) and implement Display for it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions