-
I wasn't able to find an example and the following doesn't compile: #![cfg_attr(
all(not(debug_assertions), target_os = "windows"),
windows_subsystem = "windows"
)]
use std::sync::Mutex;
struct State {
content: String
}
impl State {
fn new() -> Self {
State {
content: "test".to_string()
}
}
pub async fn test_async(&mut self) -> Result<String, String> {
Ok("test".to_string())
}
}
// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
#[tauri::command]
async fn greet(state: tauri::State<'_, Mutex< State>>,) -> Result<String, String> {
//format!("Hello, {}! You've been greeted from Rust!", name)
if let Ok(content) = state.lock().unwrap().test_async().await
{
return Ok(content.to_string());
}
else {
return Err("test".to_string());
}
}
fn main() {
let state = Mutex::new(State::new());
tauri::Builder::default()
.manage(state)
.invoke_handler(tauri::generate_handler![greet])
.run(tauri::generate_context!())
.expect("error while running tauri application");
} the above gives:
I tried multiple ways, none worked, including using Arc<RwLock> for example, if Future is not send, I can't await another async function at all? I also tried a synchronized workaround, using tauri's |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
I solved it by https://stackoverflow.com/questions/67277282/async-function-the-trait-stdmarkersend-is-not-implemented-for-stdsync |
Beta Was this translation helpful? Give feedback.
-
@shi-yan Hay, could you please share some code snippets? I faced this error bellow
|
Beta Was this translation helpful? Give feedback.
I solved it by https://stackoverflow.com/questions/67277282/async-function-the-trait-stdmarkersend-is-not-implemented-for-stdsync