Skip to main content

aws_sdk_ec2/types/
_volume_type.rs

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