Skip to main content

aws_sdk_chimesdkmessaging/types/
_error_code.rs

1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2
3/// When writing a match expression against `ErrorCode`, it is important to ensure
4/// your code is forward-compatible. That is, if a match arm handles a case for a
5/// feature that is supported by the service but has not been represented as an enum
6/// variant in a current version of SDK, your code should continue to work when you
7/// upgrade SDK to a future version in which the enum does include a variant for that
8/// feature.
9///
10/// Here is an example of how you can make a match expression forward-compatible:
11///
12/// ```text
13/// # let errorcode = unimplemented!();
14/// match errorcode {
15///     ErrorCode::AccessDenied => { /* ... */ },
16///     ErrorCode::BadRequest => { /* ... */ },
17///     ErrorCode::Conflict => { /* ... */ },
18///     ErrorCode::Forbidden => { /* ... */ },
19///     ErrorCode::NotFound => { /* ... */ },
20///     ErrorCode::PhoneNumberAssociationsExist => { /* ... */ },
21///     ErrorCode::PreconditionFailed => { /* ... */ },
22///     ErrorCode::ResourceLimitExceeded => { /* ... */ },
23///     ErrorCode::ServiceFailure => { /* ... */ },
24///     ErrorCode::ServiceUnavailable => { /* ... */ },
25///     ErrorCode::Throttled => { /* ... */ },
26///     ErrorCode::Throttling => { /* ... */ },
27///     ErrorCode::Unauthorized => { /* ... */ },
28///     ErrorCode::Unprocessable => { /* ... */ },
29///     ErrorCode::VoiceConnectorGroupAssociationsExist => { /* ... */ },
30///     other @ _ if other.as_str() == "NewFeature" => { /* handles a case for `NewFeature` */ },
31///     _ => { /* ... */ },
32/// }
33/// ```
34/// The above code demonstrates that when `errorcode` represents
35/// `NewFeature`, the execution path will lead to the second last match arm,
36/// even though the enum does not contain a variant `ErrorCode::NewFeature`
37/// in the current version of SDK. The reason is that the variable `other`,
38/// created by the `@` operator, is bound to
39/// `ErrorCode::Unknown(UnknownVariantValue("NewFeature".to_owned()))`
40/// and calling `as_str` on it yields `"NewFeature"`.
41/// This match expression is forward-compatible when executed with a newer
42/// version of SDK where the variant `ErrorCode::NewFeature` is defined.
43/// Specifically, when `errorcode` represents `NewFeature`,
44/// the execution path will hit the second last match arm as before by virtue of
45/// calling `as_str` on `ErrorCode::NewFeature` also yielding `"NewFeature"`.
46///
47/// Explicitly matching on the `Unknown` variant should
48/// be avoided for two reasons:
49/// - The inner data `UnknownVariantValue` is opaque, and no further information can be extracted.
50/// - It might inadvertently shadow other intended match arms.
51///
52#[allow(missing_docs)] // documentation missing in model
53#[non_exhaustive]
54#[derive(
55    ::std::clone::Clone, ::std::cmp::Eq, ::std::cmp::Ord, ::std::cmp::PartialEq, ::std::cmp::PartialOrd, ::std::fmt::Debug, ::std::hash::Hash,
56)]
57pub enum ErrorCode {
58    #[allow(missing_docs)] // documentation missing in model
59    AccessDenied,
60    #[allow(missing_docs)] // documentation missing in model
61    BadRequest,
62    #[allow(missing_docs)] // documentation missing in model
63    Conflict,
64    #[allow(missing_docs)] // documentation missing in model
65    Forbidden,
66    #[allow(missing_docs)] // documentation missing in model
67    NotFound,
68    #[allow(missing_docs)] // documentation missing in model
69    PhoneNumberAssociationsExist,
70    #[allow(missing_docs)] // documentation missing in model
71    PreconditionFailed,
72    #[allow(missing_docs)] // documentation missing in model
73    ResourceLimitExceeded,
74    #[allow(missing_docs)] // documentation missing in model
75    ServiceFailure,
76    #[allow(missing_docs)] // documentation missing in model
77    ServiceUnavailable,
78    #[allow(missing_docs)] // documentation missing in model
79    Throttled,
80    #[allow(missing_docs)] // documentation missing in model
81    Throttling,
82    #[allow(missing_docs)] // documentation missing in model
83    Unauthorized,
84    #[allow(missing_docs)] // documentation missing in model
85    Unprocessable,
86    #[allow(missing_docs)] // documentation missing in model
87    VoiceConnectorGroupAssociationsExist,
88    /// `Unknown` contains new variants that have been added since this code was generated.
89    #[deprecated(note = "Don't directly match on `Unknown`. See the docs on this enum for the correct way to handle unknown variants.")]
90    Unknown(crate::primitives::sealed_enum_unknown::UnknownVariantValue),
91}
92impl ::std::convert::From<&str> for ErrorCode {
93    fn from(s: &str) -> Self {
94        match s {
95            "AccessDenied" => ErrorCode::AccessDenied,
96            "BadRequest" => ErrorCode::BadRequest,
97            "Conflict" => ErrorCode::Conflict,
98            "Forbidden" => ErrorCode::Forbidden,
99            "NotFound" => ErrorCode::NotFound,
100            "PhoneNumberAssociationsExist" => ErrorCode::PhoneNumberAssociationsExist,
101            "PreconditionFailed" => ErrorCode::PreconditionFailed,
102            "ResourceLimitExceeded" => ErrorCode::ResourceLimitExceeded,
103            "ServiceFailure" => ErrorCode::ServiceFailure,
104            "ServiceUnavailable" => ErrorCode::ServiceUnavailable,
105            "Throttled" => ErrorCode::Throttled,
106            "Throttling" => ErrorCode::Throttling,
107            "Unauthorized" => ErrorCode::Unauthorized,
108            "Unprocessable" => ErrorCode::Unprocessable,
109            "VoiceConnectorGroupAssociationsExist" => ErrorCode::VoiceConnectorGroupAssociationsExist,
110            other => ErrorCode::Unknown(crate::primitives::sealed_enum_unknown::UnknownVariantValue(other.to_owned())),
111        }
112    }
113}
114impl ::std::str::FromStr for ErrorCode {
115    type Err = ::std::convert::Infallible;
116
117    fn from_str(s: &str) -> ::std::result::Result<Self, <Self as ::std::str::FromStr>::Err> {
118        ::std::result::Result::Ok(ErrorCode::from(s))
119    }
120}
121impl ErrorCode {
122    /// Returns the `&str` value of the enum member.
123    pub fn as_str(&self) -> &str {
124        match self {
125            ErrorCode::AccessDenied => "AccessDenied",
126            ErrorCode::BadRequest => "BadRequest",
127            ErrorCode::Conflict => "Conflict",
128            ErrorCode::Forbidden => "Forbidden",
129            ErrorCode::NotFound => "NotFound",
130            ErrorCode::PhoneNumberAssociationsExist => "PhoneNumberAssociationsExist",
131            ErrorCode::PreconditionFailed => "PreconditionFailed",
132            ErrorCode::ResourceLimitExceeded => "ResourceLimitExceeded",
133            ErrorCode::ServiceFailure => "ServiceFailure",
134            ErrorCode::ServiceUnavailable => "ServiceUnavailable",
135            ErrorCode::Throttled => "Throttled",
136            ErrorCode::Throttling => "Throttling",
137            ErrorCode::Unauthorized => "Unauthorized",
138            ErrorCode::Unprocessable => "Unprocessable",
139            ErrorCode::VoiceConnectorGroupAssociationsExist => "VoiceConnectorGroupAssociationsExist",
140            ErrorCode::Unknown(value) => value.as_str(),
141        }
142    }
143    /// Returns all the `&str` representations of the enum members.
144    pub const fn values() -> &'static [&'static str] {
145        &[
146            "AccessDenied",
147            "BadRequest",
148            "Conflict",
149            "Forbidden",
150            "NotFound",
151            "PhoneNumberAssociationsExist",
152            "PreconditionFailed",
153            "ResourceLimitExceeded",
154            "ServiceFailure",
155            "ServiceUnavailable",
156            "Throttled",
157            "Throttling",
158            "Unauthorized",
159            "Unprocessable",
160            "VoiceConnectorGroupAssociationsExist",
161        ]
162    }
163}
164impl ::std::convert::AsRef<str> for ErrorCode {
165    fn as_ref(&self) -> &str {
166        self.as_str()
167    }
168}
169impl ErrorCode {
170    /// Parses the enum value while disallowing unknown variants.
171    ///
172    /// Unknown variants will result in an error.
173    pub fn try_parse(value: &str) -> ::std::result::Result<Self, crate::error::UnknownVariantError> {
174        match Self::from(value) {
175            #[allow(deprecated)]
176            Self::Unknown(_) => ::std::result::Result::Err(crate::error::UnknownVariantError::new(value)),
177            known => Ok(known),
178        }
179    }
180}
181impl ::std::fmt::Display for ErrorCode {
182    fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
183        match self {
184            ErrorCode::AccessDenied => write!(f, "AccessDenied"),
185            ErrorCode::BadRequest => write!(f, "BadRequest"),
186            ErrorCode::Conflict => write!(f, "Conflict"),
187            ErrorCode::Forbidden => write!(f, "Forbidden"),
188            ErrorCode::NotFound => write!(f, "NotFound"),
189            ErrorCode::PhoneNumberAssociationsExist => write!(f, "PhoneNumberAssociationsExist"),
190            ErrorCode::PreconditionFailed => write!(f, "PreconditionFailed"),
191            ErrorCode::ResourceLimitExceeded => write!(f, "ResourceLimitExceeded"),
192            ErrorCode::ServiceFailure => write!(f, "ServiceFailure"),
193            ErrorCode::ServiceUnavailable => write!(f, "ServiceUnavailable"),
194            ErrorCode::Throttled => write!(f, "Throttled"),
195            ErrorCode::Throttling => write!(f, "Throttling"),
196            ErrorCode::Unauthorized => write!(f, "Unauthorized"),
197            ErrorCode::Unprocessable => write!(f, "Unprocessable"),
198            ErrorCode::VoiceConnectorGroupAssociationsExist => write!(f, "VoiceConnectorGroupAssociationsExist"),
199            ErrorCode::Unknown(value) => write!(f, "{value}"),
200        }
201    }
202}