Replies: 4 comments 4 replies
-
|
Currently struggling with this myself! Would love to have the clean syntax from the implicit conversion. |
Beta Was this translation helpful? Give feedback.
-
|
Not an actual answer to the "why" since I wasn't involved in the linked change, but i always thought that you're not supposed to use So from that POV, not having |
Beta Was this translation helpful? Give feedback.
-
|
This is not by design, but a consequence of Rust's rules around implementing traits for types from 3rd party crates. If you look at the code You will notice we are implementing Now if we were to try to add another impl You will notice the compiler complains. This is because This is why we have the rather verbose If you're familiar with Rust RFCs you might have noticed that this sounds and awful lot like specialization and indeed this would solve our issue, as the compiler would now accept our two |
Beta Was this translation helpful? Give feedback.
-
|
I have published [dependencies]
anyhow_serde = "1.0"This adds serde implementation for the error to serialize/deserialize the error. This allows the user to pass around the error types across the communication boundaries in apps such as Tauri without needing to convert the types. That means the https://tauri.app/develop/calling-rust/#error-handling With this feature #[tauri::command]
fn my_custom_command() -> Result<(), anyhow_serde::Error> {
std::fs::File::open("path/that/does/not/exist")?;
Ok(())
}Without this feature: each function should be migrated away from Anyhow to be usable: #[tauri::command]
fn my_custom_command() -> Result<(), String> {
std::fs::File::open("path/that/does/not/exist").map_err(|e| e.to_string)?;
Ok(())
} |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
InvokeErrorhasfrom_anyhow, which converts an anyhow error to itself. It is useful, so that user can call an internal functions that returns anyhow error from acommandfunction. However, it still requires an explicitmap_error(InvokeError::from)at the end of every fallible command. Why did tauri decide to not implementFrom<anyhow::Error>so that the conversion can be implicit?Beta Was this translation helpful? Give feedback.
All reactions