aws_sdk_macie2/types/_shared_access.rs
1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2
3/// When writing a match expression against `SharedAccess`, 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 sharedaccess = unimplemented!();
14/// match sharedaccess {
15/// SharedAccess::External => { /* ... */ },
16/// SharedAccess::Internal => { /* ... */ },
17/// SharedAccess::NotShared => { /* ... */ },
18/// SharedAccess::UnknownValue => { /* ... */ },
19/// other @ _ if other.as_str() == "NewFeature" => { /* handles a case for `NewFeature` */ },
20/// _ => { /* ... */ },
21/// }
22/// ```
23/// The above code demonstrates that when `sharedaccess` represents
24/// `NewFeature`, the execution path will lead to the second last match arm,
25/// even though the enum does not contain a variant `SharedAccess::NewFeature`
26/// in the current version of SDK. The reason is that the variable `other`,
27/// created by the `@` operator, is bound to
28/// `SharedAccess::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 `SharedAccess::NewFeature` is defined.
32/// Specifically, when `sharedaccess` represents `NewFeature`,
33/// the execution path will hit the second last match arm as before by virtue of
34/// calling `as_str` on `SharedAccess::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///
42/// _Note: `SharedAccess::Unknown` has been renamed to `::UnknownValue`._
43#[non_exhaustive]
44#[derive(
45 ::std::clone::Clone, ::std::cmp::Eq, ::std::cmp::Ord, ::std::cmp::PartialEq, ::std::cmp::PartialOrd, ::std::fmt::Debug, ::std::hash::Hash,
46)]
47pub enum SharedAccess {
48 #[allow(missing_docs)] // documentation missing in model
49 External,
50 #[allow(missing_docs)] // documentation missing in model
51 Internal,
52 #[allow(missing_docs)] // documentation missing in model
53 NotShared,
54 ///
55 /// _Note: `::Unknown` has been renamed to `::UnknownValue`._
56 UnknownValue,
57 /// `Unknown` contains new variants that have been added since this code was generated.
58 #[deprecated(note = "Don't directly match on `Unknown`. See the docs on this enum for the correct way to handle unknown variants.")]
59 Unknown(crate::primitives::sealed_enum_unknown::UnknownVariantValue),
60}
61impl ::std::convert::From<&str> for SharedAccess {
62 fn from(s: &str) -> Self {
63 match s {
64 "EXTERNAL" => SharedAccess::External,
65 "INTERNAL" => SharedAccess::Internal,
66 "NOT_SHARED" => SharedAccess::NotShared,
67 "UNKNOWN" => SharedAccess::UnknownValue,
68 other => SharedAccess::Unknown(crate::primitives::sealed_enum_unknown::UnknownVariantValue(other.to_owned())),
69 }
70 }
71}
72impl ::std::str::FromStr for SharedAccess {
73 type Err = ::std::convert::Infallible;
74
75 fn from_str(s: &str) -> ::std::result::Result<Self, <Self as ::std::str::FromStr>::Err> {
76 ::std::result::Result::Ok(SharedAccess::from(s))
77 }
78}
79impl SharedAccess {
80 /// Returns the `&str` value of the enum member.
81 pub fn as_str(&self) -> &str {
82 match self {
83 SharedAccess::External => "EXTERNAL",
84 SharedAccess::Internal => "INTERNAL",
85 SharedAccess::NotShared => "NOT_SHARED",
86 SharedAccess::UnknownValue => "UNKNOWN",
87 SharedAccess::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 &["EXTERNAL", "INTERNAL", "NOT_SHARED", "UNKNOWN"]
93 }
94}
95impl ::std::convert::AsRef<str> for SharedAccess {
96 fn as_ref(&self) -> &str {
97 self.as_str()
98 }
99}
100impl SharedAccess {
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 SharedAccess {
113 fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
114 match self {
115 SharedAccess::External => write!(f, "EXTERNAL"),
116 SharedAccess::Internal => write!(f, "INTERNAL"),
117 SharedAccess::NotShared => write!(f, "NOT_SHARED"),
118 SharedAccess::UnknownValue => write!(f, "UNKNOWN"),
119 SharedAccess::Unknown(value) => write!(f, "{}", value),
120 }
121 }
122}