bitwarden-api-api 3.0.0

Api bindings for the Bitwarden API.
Documentation
/*
 * Bitwarden Internal API
 *
 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
 *
 * The version of the OpenAPI document: latest
 *
 * Generated by: https://openapi-generator.tech
 */

use serde::{Deserialize, Deserializer, Serialize, Serializer, de::Visitor};

use crate::models;
///
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum WebAuthnPrfStatus {
    Enabled,
    Supported,
    Unsupported,

    /// Unknown value returned from the server. This is used to handle forward compatibility.
    __Unknown(i64),
}

impl WebAuthnPrfStatus {
    pub fn as_i64(&self) -> i64 {
        match self {
            Self::Enabled => 0,
            Self::Supported => 1,
            Self::Unsupported => 2,
            Self::__Unknown(v) => *v,
        }
    }

    pub fn from_i64(value: i64) -> Self {
        match value {
            0 => Self::Enabled,
            1 => Self::Supported,
            2 => Self::Unsupported,
            v => Self::__Unknown(v),
        }
    }
}

impl serde::Serialize for WebAuthnPrfStatus {
    fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
        serializer.serialize_i64(self.as_i64())
    }
}

impl<'de> serde::Deserialize<'de> for WebAuthnPrfStatus {
    fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
        struct WebAuthnPrfStatusVisitor;

        impl Visitor<'_> for WebAuthnPrfStatusVisitor {
            type Value = WebAuthnPrfStatus;

            fn expecting(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
                f.write_str("an integer")
            }

            fn visit_i64<E: serde::de::Error>(self, v: i64) -> Result<Self::Value, E> {
                Ok(WebAuthnPrfStatus::from_i64(v))
            }

            fn visit_u64<E: serde::de::Error>(self, v: u64) -> Result<Self::Value, E> {
                Ok(WebAuthnPrfStatus::from_i64(v as i64))
            }
        }

        deserializer.deserialize_i64(WebAuthnPrfStatusVisitor)
    }
}

impl std::fmt::Display for WebAuthnPrfStatus {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self.as_i64())
    }
}
impl Default for WebAuthnPrfStatus {
    fn default() -> WebAuthnPrfStatus {
        Self::Enabled
    }
}