[rust] Errors implementing Deserializer/Serializer on Error enum #8805
-
I'm writing commands. Followed this section https://tauri.app/v1/guides/features/command#error-handling #[derive(Debug, thiserror::Error)]
enum Error {
#[error(transparent)]
Io(#[from] std::io::Error)
}
// we must manually implement serde::Serialize
impl serde::Serialize for Error {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::ser::Serializer,
{
serializer.serialize_str(self.to_string().as_ref())
}
}
// Commands
#[tauri::command]
fn writeFile(fileData: FileData) -> Result<(), Error> {
ensure_dir("./data");
let mut file = fs::File::create(fileData.path).expect("IO Error");
file.write(fileData.data.as_bytes()).expect("IO Error");
Ok(())
}
Starting with Rust and Tauri. Give me a hand please! 😁🤝🔥💛🩵 |
Beta Was this translation helpful? Give feedback.
Answered by
FabianLars
Feb 7, 2024
Replies: 1 comment 1 reply
-
Please add I will keep this in mind for the new docs, thanks :) |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
angelhdzmultimedia
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Please add
thiserror = "1"
to the dependencies section in Cargo.toml.I will keep this in mind for the new docs, thanks :)