tauri_plugin_android_fs/
error.rs

1use serde::{ser::Serializer, Serialize};
2
3pub type Result<T> = std::result::Result<T, crate::Error>;
4
5/// Path error
6#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy, thiserror::Error)]
7#[non_exhaustive]
8pub enum PathError {
9
10    /// When the path contains consecutive separators.
11    #[error("The path contains consecutive separators.")]
12    ConsecutiveSeparator,
13
14    /// When the path does not contain a filename.
15    #[error("The path does not contain a filename.")]
16    DoesNotContainFileName,
17
18    /// When the path does not contain a subdirectory.
19    #[error("The path does not contain a subdirectory.")]
20    DoesNotContainSubDir,
21
22    /// When the path is empty.
23    #[error("The path is empty.")]
24    Empty,
25}
26
27#[derive(Debug, thiserror::Error)]
28#[non_exhaustive]
29pub enum Error {
30
31    #[error("This device is not running Android. This plugin is only supported on Android.")]
32    NotAndroid,
33
34    #[error(transparent)]
35    Path(#[from] PathError),
36
37    #[error(transparent)]
38    Io(#[from] std::io::Error),
39  
40    #[error("{0}")]
41    PluginInvoke(String),
42}
43
44#[cfg(target_os = "android")]
45impl From<tauri::plugin::mobile::PluginInvokeError> for crate::Error {
46
47    fn from(value: tauri::plugin::mobile::PluginInvokeError) -> Self {
48        Self::PluginInvoke(format!("{value}"))
49    }
50}
51
52impl Serialize for crate::Error {
53
54    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
55    where
56        S: Serializer,
57    {
58        serializer.serialize_str(self.to_string().as_ref())
59    }
60}