Skip to main content

tauri_plugin_barcode_scanner/
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 the result type returned by this crate's functions.
8pub type Result<T> = std::result::Result<T, Error>;
9
10/// The error type returned by this crate's APIs. Serialized as its [`Display`](std::fmt::Display)
11/// string when it crosses the IPC boundary.
12#[derive(Debug, thiserror::Error)]
13pub enum Error {
14    /// An I/O error occurred.
15    #[error(transparent)]
16    Io(#[from] std::io::Error),
17    /// Failed to run a command on the mobile plugin implementation (Kotlin on Android, Swift on iOS).
18    #[cfg(mobile)]
19    #[error(transparent)]
20    PluginInvoke(#[from] tauri::plugin::mobile::PluginInvokeError),
21}
22
23impl Serialize for Error {
24    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
25    where
26        S: Serializer,
27    {
28        serializer.serialize_str(self.to_string().as_ref())
29    }
30}