Skip to main content

tauri_plugin_biometric/
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 [`Result`](std::result::Result) with the error type [`Error`].
8pub type Result<T> = std::result::Result<T, Error>;
9
10/// The error types returned by this plugin.
11#[derive(Debug, thiserror::Error)]
12pub enum Error {
13    /// An I/O error occurred.
14    #[error(transparent)]
15    Io(#[from] std::io::Error),
16    /// The invocation of the underlying Android or iOS plugin failed, for example because
17    /// biometric authentication was unavailable, was not enrolled, failed, or was canceled by
18    /// the user.
19    #[cfg(mobile)]
20    #[error(transparent)]
21    PluginInvoke(#[from] tauri::plugin::mobile::PluginInvokeError),
22}
23
24impl Serialize for Error {
25    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
26    where
27        S: Serializer,
28    {
29        serializer.serialize_str(self.to_string().as_ref())
30    }
31}