aws_sdk_ec2/types/_ipam_compliance_status.rs
1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2
3/// When writing a match expression against `IpamComplianceStatus`, 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 ipamcompliancestatus = unimplemented!();
14/// match ipamcompliancestatus {
15/// IpamComplianceStatus::Compliant => { /* ... */ },
16/// IpamComplianceStatus::Ignored => { /* ... */ },
17/// IpamComplianceStatus::Noncompliant => { /* ... */ },
18/// IpamComplianceStatus::Unmanaged => { /* ... */ },
19/// other @ _ if other.as_str() == "NewFeature" => { /* handles a case for `NewFeature` */ },
20/// _ => { /* ... */ },
21/// }
22/// ```
23/// The above code demonstrates that when `ipamcompliancestatus` represents
24/// `NewFeature`, the execution path will lead to the second last match arm,
25/// even though the enum does not contain a variant `IpamComplianceStatus::NewFeature`
26/// in the current version of SDK. The reason is that the variable `other`,
27/// created by the `@` operator, is bound to
28/// `IpamComplianceStatus::Unknown(UnknownVariantValue("NewFeature".to_owned()))`
29/// and calling `as_str` on it yields `"NewFeature"`.
30/// This match expression is forward-compatible when executed with a newer
31/// version of SDK where the variant `IpamComplianceStatus::NewFeature` is defined.
32/// Specifically, when `ipamcompliancestatus` represents `NewFeature`,
33/// the execution path will hit the second last match arm as before by virtue of
34/// calling `as_str` on `IpamComplianceStatus::NewFeature` also yielding `"NewFeature"`.
35///
36/// Explicitly matching on the `Unknown` variant should
37/// be avoided for two reasons:
38/// - The inner data `UnknownVariantValue` is opaque, and no further information can be extracted.
39/// - It might inadvertently shadow other intended match arms.
40///
41#[allow(missing_docs)] // documentation missing in model
42#[non_exhaustive]
43#[derive(
44 ::std::clone::Clone, ::std::cmp::Eq, ::std::cmp::Ord, ::std::cmp::PartialEq, ::std::cmp::PartialOrd, ::std::fmt::Debug, ::std::hash::Hash,
45)]
46pub enum IpamComplianceStatus {
47 #[allow(missing_docs)] // documentation missing in model
48 Compliant,
49 #[allow(missing_docs)] // documentation missing in model
50 Ignored,
51 #[allow(missing_docs)] // documentation missing in model
52 Noncompliant,
53 #[allow(missing_docs)] // documentation missing in model
54 Unmanaged,
55 /// `Unknown` contains new variants that have been added since this code was generated.
56 #[deprecated(note = "Don't directly match on `Unknown`. See the docs on this enum for the correct way to handle unknown variants.")]
57 Unknown(crate::primitives::sealed_enum_unknown::UnknownVariantValue),
58}
59impl ::std::convert::From<&str> for IpamComplianceStatus {
60 fn from(s: &str) -> Self {
61 match s {
62 "compliant" => IpamComplianceStatus::Compliant,
63 "ignored" => IpamComplianceStatus::Ignored,
64 "noncompliant" => IpamComplianceStatus::Noncompliant,
65 "unmanaged" => IpamComplianceStatus::Unmanaged,
66 other => IpamComplianceStatus::Unknown(crate::primitives::sealed_enum_unknown::UnknownVariantValue(other.to_owned())),
67 }
68 }
69}
70impl ::std::str::FromStr for IpamComplianceStatus {
71 type Err = ::std::convert::Infallible;
72
73 fn from_str(s: &str) -> ::std::result::Result<Self, <Self as ::std::str::FromStr>::Err> {
74 ::std::result::Result::Ok(IpamComplianceStatus::from(s))
75 }
76}
77impl IpamComplianceStatus {
78 /// Returns the `&str` value of the enum member.
79 pub fn as_str(&self) -> &str {
80 match self {
81 IpamComplianceStatus::Compliant => "compliant",
82 IpamComplianceStatus::Ignored => "ignored",
83 IpamComplianceStatus::Noncompliant => "noncompliant",
84 IpamComplianceStatus::Unmanaged => "unmanaged",
85 IpamComplianceStatus::Unknown(value) => value.as_str(),
86 }
87 }
88 /// Returns all the `&str` representations of the enum members.
89 pub const fn values() -> &'static [&'static str] {
90 &["compliant", "ignored", "noncompliant", "unmanaged"]
91 }
92}
93impl ::std::convert::AsRef<str> for IpamComplianceStatus {
94 fn as_ref(&self) -> &str {
95 self.as_str()
96 }
97}
98impl IpamComplianceStatus {
99 /// Parses the enum value while disallowing unknown variants.
100 ///
101 /// Unknown variants will result in an error.
102 pub fn try_parse(value: &str) -> ::std::result::Result<Self, crate::error::UnknownVariantError> {
103 match Self::from(value) {
104 #[allow(deprecated)]
105 Self::Unknown(_) => ::std::result::Result::Err(crate::error::UnknownVariantError::new(value)),
106 known => Ok(known),
107 }
108 }
109}
110impl ::std::fmt::Display for IpamComplianceStatus {
111 fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
112 match self {
113 IpamComplianceStatus::Compliant => write!(f, "compliant"),
114 IpamComplianceStatus::Ignored => write!(f, "ignored"),
115 IpamComplianceStatus::Noncompliant => write!(f, "noncompliant"),
116 IpamComplianceStatus::Unmanaged => write!(f, "unmanaged"),
117 IpamComplianceStatus::Unknown(value) => write!(f, "{}", value),
118 }
119 }
120}