Skip to main content

tauri_plugin_nfc/
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, ser::Serializer};
6
7/// Alias for a [`std::result::Result`] with the error type [`Error`].
8pub type Result<T> = std::result::Result<T, Error>;
9
10/// Errors returned by the NFC plugin.
11///
12/// Serializes to the error message string, so it can be returned directly from a command.
13#[derive(Debug, thiserror::Error)]
14pub enum Error {
15    /// An I/O error happened.
16    #[error(transparent)]
17    Io(#[from] std::io::Error),
18    /// The call to the Android or iOS plugin implementation failed,
19    /// either because the arguments could not be serialized, the response could not be
20    /// deserialized or the native side rejected the call (e.g. NFC is unavailable
21    /// or the tag could not be read or written).
22    #[cfg(mobile)]
23    #[error(transparent)]
24    PluginInvoke(#[from] tauri::plugin::mobile::PluginInvokeError),
25}
26
27impl Serialize for Error {
28    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
29    where
30        S: Serializer,
31    {
32        serializer.serialize_str(self.to_string().as_ref())
33    }
34}