tauri_plugin_global_shortcut/
error.rs

1// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
2// SPDX-License-Identifier: Apache-2.0
3// SPDX-License-Identifier: MIT
4
5use serde::{Serialize, Serializer};
6
7#[derive(Debug, thiserror::Error)]
8#[non_exhaustive]
9pub enum Error {
10    #[error("{0}")]
11    GlobalHotkey(String),
12    #[error(transparent)]
13    RecvError(#[from] std::sync::mpsc::RecvError),
14    #[error(transparent)]
15    Tauri(#[from] tauri::Error),
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
27impl From<global_hotkey::Error> for Error {
28    fn from(value: global_hotkey::Error) -> Self {
29        Self::GlobalHotkey(value.to_string())
30    }
31}
32
33impl From<global_hotkey::hotkey::HotKeyParseError> for Error {
34    fn from(value: global_hotkey::hotkey::HotKeyParseError) -> Self {
35        Self::GlobalHotkey(value.to_string())
36    }
37}