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 CipherType {
    Login,
    SecureNote,
    Card,
    Identity,
    SSHKey,
    BankAccount,
    DriversLicense,
    Passport,

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

impl CipherType {
    pub fn as_i64(&self) -> i64 {
        match self {
            Self::Login => 1,
            Self::SecureNote => 2,
            Self::Card => 3,
            Self::Identity => 4,
            Self::SSHKey => 5,
            Self::BankAccount => 6,
            Self::DriversLicense => 7,
            Self::Passport => 8,
            Self::__Unknown(v) => *v,
        }
    }

    pub fn from_i64(value: i64) -> Self {
        match value {
            1 => Self::Login,
            2 => Self::SecureNote,
            3 => Self::Card,
            4 => Self::Identity,
            5 => Self::SSHKey,
            6 => Self::BankAccount,
            7 => Self::DriversLicense,
            8 => Self::Passport,
            v => Self::__Unknown(v),
        }
    }
}

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

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

        impl Visitor<'_> for CipherTypeVisitor {
            type Value = CipherType;

            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(CipherType::from_i64(v))
            }

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

        deserializer.deserialize_i64(CipherTypeVisitor)
    }
}

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