workos 1.0.0

Official Rust SDK for the WorkOS API
Documentation
// Code generated by oagen. DO NOT EDIT.

use serde::{Deserialize, Serialize};
use std::fmt;
use std::str::FromStr;

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum UserSessionsAuthMethod {
    CrossAppAuth,
    ExternalAuth,
    Impersonation,
    MagicCode,
    MigratedSession,
    OAuth,
    Passkey,
    Password,
    SSO,
    Unknown,
    /// Wire value not recognized by this SDK version. The original
    /// string is preserved verbatim. WorkOS may add new enum values
    /// server-side; matching on this variant lets callers handle
    /// forward-compatible values without panicking.
    Unrecognized(String),
}

impl UserSessionsAuthMethod {
    /// Canonical wire string for this value. For [`Self::Unrecognized`] returns the
    /// original wire value as received from the API.
    #[allow(deprecated)]
    pub fn as_str(&self) -> &str {
        match self {
            Self::CrossAppAuth => "cross_app_auth",
            Self::ExternalAuth => "external_auth",
            Self::Impersonation => "impersonation",
            Self::MagicCode => "magic_code",
            Self::MigratedSession => "migrated_session",
            Self::OAuth => "oauth",
            Self::Passkey => "passkey",
            Self::Password => "password",
            Self::SSO => "sso",
            Self::Unknown => "unknown",
            Self::Unrecognized(s) => s.as_str(),
        }
    }
}

impl fmt::Display for UserSessionsAuthMethod {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.write_str(self.as_str())
    }
}

impl AsRef<str> for UserSessionsAuthMethod {
    fn as_ref(&self) -> &str {
        self.as_str()
    }
}

impl FromStr for UserSessionsAuthMethod {
    type Err = std::convert::Infallible;
    #[allow(deprecated)]
    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Ok(match s {
            "cross_app_auth" => Self::CrossAppAuth,
            "external_auth" => Self::ExternalAuth,
            "impersonation" => Self::Impersonation,
            "magic_code" => Self::MagicCode,
            "migrated_session" => Self::MigratedSession,
            "oauth" => Self::OAuth,
            "passkey" => Self::Passkey,
            "password" => Self::Password,
            "sso" => Self::SSO,
            "unknown" => Self::Unknown,
            other => Self::Unrecognized(other.to_string()),
        })
    }
}

impl From<String> for UserSessionsAuthMethod {
    fn from(s: String) -> Self {
        // Reuse the original `String` allocation in the fallback branch.
        match Self::from_str(&s) {
            Ok(Self::Unrecognized(_)) => Self::Unrecognized(s),
            Ok(other) => other,
        }
    }
}

impl From<&str> for UserSessionsAuthMethod {
    fn from(s: &str) -> Self {
        Self::from_str(s).unwrap_or_else(|_| Self::Unrecognized(s.to_string()))
    }
}

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

impl<'de> Deserialize<'de> for UserSessionsAuthMethod {
    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
        let s = String::deserialize(deserializer)?;
        Ok(Self::from(s))
    }
}