Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
1 of 3 tasks
kawadakk opened this issue Jan 19, 2024 · 1 comment
Open
1 of 3 tasks
Labels

Comments

@kawadakk
Copy link
Contributor

kawadakk commented Jan 19, 2024

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
@kawadakk kawadakk added the bug label Jan 19, 2024
@kawadakk
Copy link
Contributor Author

This could be fixed by adding an impl From<&Classes> for Classes, but I'm curious why html! is using From instead of IntoPropValue (as in component props) in the first place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant