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 SSOProvider {
    AppleOAuth,
    BitbucketOAuth,
    GitHubOAuth,
    GitLabOAuth,
    GoogleOAuth,
    IntuitOAuth,
    LinkedInOAuth,
    MicrosoftOAuth,
    SalesforceOAuth,
    SlackOAuth,
    VercelMarketplaceOAuth,
    VercelOAuth,
    XeroOAuth,
    /// 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.
    Unknown(String),
}

impl SSOProvider {
    /// Canonical wire string for this value. For [`Self::Unknown`] returns the
    /// original wire value as received from the API.
    #[allow(deprecated)]
    pub fn as_str(&self) -> &str {
        match self {
            Self::AppleOAuth => "AppleOAuth",
            Self::BitbucketOAuth => "BitbucketOAuth",
            Self::GitHubOAuth => "GitHubOAuth",
            Self::GitLabOAuth => "GitLabOAuth",
            Self::GoogleOAuth => "GoogleOAuth",
            Self::IntuitOAuth => "IntuitOAuth",
            Self::LinkedInOAuth => "LinkedInOAuth",
            Self::MicrosoftOAuth => "MicrosoftOAuth",
            Self::SalesforceOAuth => "SalesforceOAuth",
            Self::SlackOAuth => "SlackOAuth",
            Self::VercelMarketplaceOAuth => "VercelMarketplaceOAuth",
            Self::VercelOAuth => "VercelOAuth",
            Self::XeroOAuth => "XeroOAuth",
            Self::Unknown(s) => s.as_str(),
        }
    }
}

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

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

impl FromStr for SSOProvider {
    type Err = std::convert::Infallible;
    #[allow(deprecated)]
    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Ok(match s {
            "AppleOAuth" => Self::AppleOAuth,
            "BitbucketOAuth" => Self::BitbucketOAuth,
            "GitHubOAuth" => Self::GitHubOAuth,
            "GitLabOAuth" => Self::GitLabOAuth,
            "GoogleOAuth" => Self::GoogleOAuth,
            "IntuitOAuth" => Self::IntuitOAuth,
            "LinkedInOAuth" => Self::LinkedInOAuth,
            "MicrosoftOAuth" => Self::MicrosoftOAuth,
            "SalesforceOAuth" => Self::SalesforceOAuth,
            "SlackOAuth" => Self::SlackOAuth,
            "VercelMarketplaceOAuth" => Self::VercelMarketplaceOAuth,
            "VercelOAuth" => Self::VercelOAuth,
            "XeroOAuth" => Self::XeroOAuth,
            other => Self::Unknown(other.to_string()),
        })
    }
}

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

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

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

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