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
use dioxus::prelude::*;#[server]asyncfnsave_dog(image:String) -> Result<(),ServerFnError>{Ok(())}#[component]fnDogView() -> Element{let src = use_signal(|| "https://images.dog.ceo/breeds/pitbull/dog-3981540_1280.jpg");let save = asyncmove |_| {save_dog(src.cloned().to_owned()).await.unwrap();};rsx!{
img { src }
div {
button { onclick: save,"save!"}}}}
Error:
error:async closure does not implement `FnMut` because it captures state from its environment
--> src/main.rs:104:16
|
104 | let save = asyncmove |_| {
| ^^^^^^^^^^^^^^
...
113 | button{onclick: save, "save!" }
| ------------- required by a bound introduced by this call
|
= note: required for `Callback<dioxus::prelude::Event<MouseData>>` to implement `SuperFrom<{async closure@src/main.rs:104:16:104:30},MarkerWrapper<dioxus::dioxus_core::events::AsyncMarker>>`
= note: required for `{async closure@src/main.rs:104:16:104:30}` to implement `SuperInto<Callback<dioxus::prelude::Event<MouseData>>,MarkerWrapper<dioxus::dioxus_core::events::AsyncMarker>>`
But it works when you use an inner async block instead:
- let save = async move |_| {+ let save = move |_| async move {
save_dog(src.cloned().to_owned()).await.unwrap();
};
Expected behavior
Async closures has been stabilized, so it should be expected that it works with Dioxus.
Async closures are still unstable and can only be used in the nightly edition of rust. Dioxus could accept async closures, but all of the async closure logic would need to be gated under the nightly version of rust
Problem
Steps To Reproduce
Error:
But it works when you use an inner async block instead:
Expected behavior
Async closures has been stabilized, so it should be expected that it works with Dioxus.
Screenshots
Environment:
web
Questionnaire
The text was updated successfully, but these errors were encountered: