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