tauri_plugin_torchlight/
error.rs1use serde::{ser::Serializer, Serialize};
2
3pub type Result<T> = std::result::Result<T, Error>;
4
5#[derive(Debug, thiserror::Error)]
6pub enum Error {
7 #[cfg(mobile)]
9 #[error(transparent)]
10 PluginInvoke(#[from] tauri::plugin::mobile::PluginInvokeError),
11
12 #[cfg(desktop)]
14 #[error("torchlight is only supported on Android and iOS; this is a desktop platform")]
15 Unsupported,
16}
17
18impl Serialize for Error {
19 fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
20 where
21 S: Serializer,
22 {
23 serializer.serialize_str(self.to_string().as_ref())
24 }
25}
26
27#[cfg(test)]
28mod tests {
29 use super::*;
30
31 #[cfg(desktop)]
32 #[test]
33 fn unsupported_serializes_to_a_human_readable_string() {
34 let json = serde_json::to_string(&Error::Unsupported).unwrap();
35 assert_eq!(
36 json,
37 "\"torchlight is only supported on Android and iOS; this is a desktop platform\""
38 );
39 }
40}