tauri_plugin_android_fs/models/
error.rs

1use std::borrow::Cow;
2use serde::{ser::Serializer, Serialize};
3
4#[derive(Debug, Clone, thiserror::Error)]
5#[error("{msg}")]
6pub struct Error {
7    pub(crate) msg: Cow<'static, str>
8}
9
10impl Error {
11
12    #[allow(unused)]
13    pub(crate) fn with(msg: impl Into<Cow<'static, str>>) -> Self {
14        Self { msg: msg.into() }
15    }
16}
17
18#[cfg(target_os = "android")]
19impl From<tauri::plugin::mobile::PluginInvokeError> for crate::Error {
20
21    fn from(value: tauri::plugin::mobile::PluginInvokeError) -> Self {
22        Self { msg: Cow::Owned(value.to_string())}
23    }
24}
25
26impl From<std::io::Error> for crate::Error {
27
28    fn from(value: std::io::Error) -> Self {
29        Self { msg: Cow::Owned(value.to_string())}
30    }
31}
32
33impl<W> From<std::io::IntoInnerError<W>> for crate::Error {
34
35    fn from(value: std::io::IntoInnerError<W>) -> Self {
36        Self { msg: Cow::Owned(value.error().to_string())}
37    }
38}
39
40impl From<serde_json::Error> for crate::Error {
41
42    fn from(value: serde_json::Error) -> Self {
43        Self { msg: Cow::Owned(value.to_string())}
44    }
45}
46
47impl From<tauri::Error> for crate::Error {
48
49    fn from(value: tauri::Error) -> Self {
50        Self { msg: Cow::Owned(value.to_string())}
51    }
52}
53
54impl Serialize for crate::Error {
55
56    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
57    where
58        S: Serializer,
59    {
60        serializer.serialize_str(&self.msg)
61    }
62}