Skip to content

When passing Classes in html!, component props don't need .clone(), but element props do #3589

Open
@kawadakk

Description

@kawadakk

Problem
You can write prop_name={&value} when passing a prop of type Classes to a component (because Classes implements ImplicitClone), but you can't when passing it to an element, requiring you to write prop_name={value.clone()} instead, which seems inconsistent.

Steps To Reproduce

#[derive(Properties, PartialEq)]
struct Props {
    class: Classes,
}

#[function_component]
fn Foo1(props: &Props) -> Html {
    html! {
        <a class={&props.class} />
    }
}

#[function_component]
fn Foo2(props: &Props) -> Html {
    html! {
        <Foo1 class={&props.class} />
    }
}

Expected behavior
Successful compilation

Screenshots

error[E0277]: the trait bound `yew::Classes: std::convert::From<&yew::Classes>` is not satisfied
  --> .../foo.rs:69:19
   |
68 | /     html! {
69 | |         <a class={&props.class} />
   | |                   ^^^^^^^^^^^^ the trait `std::convert::From<&yew::Classes>` is not implemented for `yew::Classes`
70 | |     }
   | |_____- required by a bound introduced by this call
   |
   = note: required for `&yew::Classes` to implement `std::convert::Into<yew::Classes>`
help: consider dereferencing here
   |
69 |         <a class={*&props.class} />
   |                   +

Environment:

  • Yew version: v0.21
  • Rust version: nightly
  • Target, if relevant: wasm32-unknown-unknown

Questionnaire

  • I'm interested in fixing this myself but don't know where to start
  • I would like to fix and I have a solution
  • I don't have time to fix this right now, but maybe later

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