sycamore-rs / sycamore

A library for creating reactive web apps in Rust and WebAssembly
https://sycamore-rs.netlify.app
MIT License
2.79k stars 148 forks source link

Nested component using string error #653

Closed ys2rice2yangsong closed 8 months ago

ys2rice2yangsong commented 8 months ago

Describe the bug A clear and concise description of what the bug is.

To Reproduce Steps to reproduce the behavior:

[component(inline_props)]

fn T(cx:Scope,title: String, level: i32) -> View { let tt = title.clone();

view!{
    cx,
    (
        if level<5 {
            view!{
                cx,
                T(
                    title=tt,
                    level=level+1
                )
            }
        } else {
            view!{
                cx,
                p{
                    (tt)
                }
            }
        }
    )
}

}

error info: cannot move out of tt_clone, a captured variable in an FnMut closure tt_clone is moved hererustcClick for full compiler diagnostic main.rs(25, 9): captured outer variable main.rs(26, 5): captured by this FnMut closure main.rs(33, 31): variable moved due to use in closure main.rs(33, 31): move occurs because tt_clone has type String, which does not implement the Copy trait

Expected behavior A clear and concise description of what you expected to happen.

Screenshots If applicable, add screenshots to help explain your problem.

Environment

Additional context Add any other context about the problem here.

lukechu10 commented 8 months ago

Where is tt_clone? I believe what you want is title.clone() inside the inner view. Please reopen if this doesn't solve your issue.