tauri_plugin_android_fs/
error.rs

1use std::borrow::Cow;
2use serde::{ser::Serializer, Serialize};
3
4
5pub type Result<T> = std::result::Result<T, crate::Error>;
6
7#[derive(Debug, Clone, thiserror::Error)]
8#[error("{msg}")]
9pub struct Error {
10    pub(crate) msg: Cow<'static, str>
11}
12
13#[cfg(target_os = "android")]
14impl From<tauri::plugin::mobile::PluginInvokeError> for crate::Error {
15
16    fn from(value: tauri::plugin::mobile::PluginInvokeError) -> Self {
17        Self { msg: Cow::Owned(value.to_string())}
18    }
19}
20
21impl From<std::io::Error> for crate::Error {
22
23    fn from(value: std::io::Error) -> Self {
24        Self { msg: Cow::Owned(value.to_string())}
25    }
26}
27
28impl From<serde_json::Error> for crate::Error {
29
30    fn from(value: serde_json::Error) -> Self {
31        Self { msg: Cow::Owned(value.to_string())}
32    }
33}
34
35impl Serialize for crate::Error {
36
37    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
38    where
39        S: Serializer,
40    {
41        serializer.serialize_str(&self.msg)
42    }
43}