intendednull/yewdux

Cannot move out of ...

TiemenSch opened this issue · 2 comments

I can't seem to wrap my head around why the following is happening:

#[derive(Clone, Debug, Default, PartialEq, Store)]
pub struct Foo {
    foo: String,
}
impl Foo {
    pub fn update(&mut self, new: String) {
        self.foo = new;
    }
}

#[function_component]
pub fn Tabs() -> Html {
    let (foo, foo_dp) = use_store::<Foo>();

    let id = uuid::Uuid::new_v4().to_string();
    let update = {
        let id = id.clone();
        foo_dp.reduce_mut_callback_with(|foo, e: MouseEvent| {
            foo.update(id);
        })
    };

    //    html!  and friends ...

Resulting in an error on the update call stating:

cannot move out of `id`, a captured variable in an `Fn` closure
move occurs because `id` has type `std::string::String`, which does not implement the `Copy` trait

With the latest yewdux and yew as dependencies.

Any ideas?

Perhaps to clarify, this does compile and I can't seem to find the difference

let timezone = timezone.clone();

It was the move |...| before the closure arguments, although I could've sworn I tried that this morning, too.

Sorry to have bothered you with this.