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
13impl Error {
14
15    #[allow(unused)]
16    pub(crate) fn with(msg: impl Into<Cow<'static, str>>) -> Self {
17        Self { msg: msg.into() }
18    }
19}
20
21#[cfg(target_os = "android")]
22impl From<tauri::plugin::mobile::PluginInvokeError> for crate::Error {
23
24    fn from(value: tauri::plugin::mobile::PluginInvokeError) -> Self {
25        Self { msg: Cow::Owned(value.to_string())}
26    }
27}
28
29impl From<std::io::Error> for crate::Error {
30
31    fn from(value: std::io::Error) -> Self {
32        Self { msg: Cow::Owned(value.to_string())}
33    }
34}
35
36impl<W: std::io::Write> From<std::io::IntoInnerError<W>> for crate::Error {
37
38    fn from(value: std::io::IntoInnerError<W>) -> Self {
39        Self { msg: Cow::Owned(value.to_string())}
40    }
41}
42
43impl From<serde_json::Error> for crate::Error {
44
45    fn from(value: serde_json::Error) -> Self {
46        Self { msg: Cow::Owned(value.to_string())}
47    }
48}
49
50impl Serialize for crate::Error {
51
52    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
53    where
54        S: Serializer,
55    {
56        serializer.serialize_str(&self.msg)
57    }
58}