Skip to main content

workos/enums/
invitation_created_data_state.rs

1// This file is auto-generated by oagen. Do not edit.
2
3use serde::{Deserialize, Serialize};
4use std::fmt;
5use std::str::FromStr;
6
7#[derive(Debug, Clone, PartialEq, Eq, Hash)]
8#[non_exhaustive]
9pub enum InvitationCreatedDataState {
10    Pending,
11    Accepted,
12    Expired,
13    Revoked,
14    /// Wire value not recognized by this SDK version. The original
15    /// string is preserved verbatim. WorkOS may add new enum values
16    /// server-side; matching on this variant lets callers handle
17    /// forward-compatible values without panicking.
18    Unknown(String),
19}
20
21impl InvitationCreatedDataState {
22    /// Canonical wire string for this value. For [`Self::Unknown`] returns the
23    /// original wire value as received from the API.
24    #[allow(deprecated)]
25    pub fn as_str(&self) -> &str {
26        match self {
27            Self::Pending => "pending",
28            Self::Accepted => "accepted",
29            Self::Expired => "expired",
30            Self::Revoked => "revoked",
31            Self::Unknown(s) => s.as_str(),
32        }
33    }
34}
35
36impl fmt::Display for InvitationCreatedDataState {
37    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
38        f.write_str(self.as_str())
39    }
40}
41
42impl AsRef<str> for InvitationCreatedDataState {
43    fn as_ref(&self) -> &str {
44        self.as_str()
45    }
46}
47
48impl FromStr for InvitationCreatedDataState {
49    type Err = std::convert::Infallible;
50    #[allow(deprecated)]
51    fn from_str(s: &str) -> Result<Self, Self::Err> {
52        Ok(match s {
53            "pending" => Self::Pending,
54            "accepted" => Self::Accepted,
55            "expired" => Self::Expired,
56            "revoked" => Self::Revoked,
57            other => Self::Unknown(other.to_string()),
58        })
59    }
60}
61
62impl From<String> for InvitationCreatedDataState {
63    fn from(s: String) -> Self {
64        // Reuse the original `String` allocation in the fallback branch.
65        match Self::from_str(&s) {
66            Ok(Self::Unknown(_)) => Self::Unknown(s),
67            Ok(other) => other,
68        }
69    }
70}
71
72impl From<&str> for InvitationCreatedDataState {
73    fn from(s: &str) -> Self {
74        Self::from_str(s).unwrap_or_else(|_| Self::Unknown(s.to_string()))
75    }
76}
77
78impl Serialize for InvitationCreatedDataState {
79    fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
80        serializer.serialize_str(self.as_str())
81    }
82}
83
84impl<'de> Deserialize<'de> for InvitationCreatedDataState {
85    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
86        let s = String::deserialize(deserializer)?;
87        Ok(Self::from(s))
88    }
89}