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