You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey everyone. I am trying to render a vector. However, I am getting this error:
error[E0382]: borrow of moved value: `features`
--> src/components/banner.rs:55:14
|
13 |let features = use_state(|| vec![]);| -------- move occurs because `features` has type`yew::UseStateHandle<Vec<Feature>>`, which does not implement the `Copy` trait
14 |
15 | use_effect_with_deps(move |_| {
| -------- value moved into closure here
16 |let dispatch = dispatch.clone();
17 |let features = features.clone();
| -------- variable moved due to use in closure
...
55 | {features
| ______________^
56 ||.iter()
||___________________^ value borrowed here after move
I am trying to fetch data from an endpoint and set the response into the features vector state. However, I wonder why I am getting this error, and using features.clone().iter() instead of features.iter() didn't work.
Note: I am new to Rust, I know a little about memory management in Rust, but a proficient fella in React and its ecosystem. I am transitioning into the Rust world. Probably, I am not going back to coding in javascript, again!
Edit: It seems like move took ownership of the features state variable, and features.iter() is outside the move and probably trying to change it, that's why it threw this error. However, the value of features is not changing outside move. Then, why complain though?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hey everyone. I am trying to render a vector. However, I am getting this error:
The component I built;
I am trying to fetch data from an endpoint and set the response into the
features
vector state. However, I wonder why I am getting this error, and usingfeatures.clone().iter()
instead offeatures.iter()
didn't work.Note: I am new to Rust, I know a little about memory management in Rust, but a proficient fella in React and its ecosystem. I am transitioning into the Rust world. Probably, I am not going back to coding in javascript, again!
Edit: It seems like
move
took ownership of thefeatures
state variable, andfeatures.iter()
is outside the move and probably trying to change it, that's why it threw this error. However, the value offeatures
is not changing outsidemove
. Then, why complain though?Beta Was this translation helpful? Give feedback.
All reactions