aws_sdk_machinelearning/types/
_sort_order.rs

1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2
3/// When writing a match expression against `SortOrder`, 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 sortorder = unimplemented!();
14/// match sortorder {
15///     SortOrder::Asc => { /* ... */ },
16///     SortOrder::Dsc => { /* ... */ },
17///     other @ _ if other.as_str() == "NewFeature" => { /* handles a case for `NewFeature` */ },
18///     _ => { /* ... */ },
19/// }
20/// ```
21/// The above code demonstrates that when `sortorder` represents
22/// `NewFeature`, the execution path will lead to the second last match arm,
23/// even though the enum does not contain a variant `SortOrder::NewFeature`
24/// in the current version of SDK. The reason is that the variable `other`,
25/// created by the `@` operator, is bound to
26/// `SortOrder::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 `SortOrder::NewFeature` is defined.
30/// Specifically, when `sortorder` represents `NewFeature`,
31/// the execution path will hit the second last match arm as before by virtue of
32/// calling `as_str` on `SortOrder::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 sort order specified in a listing condition. Possible values include the following:</p>
40/// <ul>
41/// <li>
42/// <p>
43/// <code>asc</code> - Present the information in ascending order (from A-Z).</p>
44/// </li>
45/// <li>
46/// <p>
47/// <code>dsc</code> - Present the information in descending order (from Z-A).</p>
48/// </li>
49/// </ul>
50#[non_exhaustive]
51#[derive(
52    ::std::clone::Clone, ::std::cmp::Eq, ::std::cmp::Ord, ::std::cmp::PartialEq, ::std::cmp::PartialOrd, ::std::fmt::Debug, ::std::hash::Hash,
53)]
54pub enum SortOrder {
55    #[allow(missing_docs)] // documentation missing in model
56    Asc,
57    #[allow(missing_docs)] // documentation missing in model
58    Dsc,
59    /// `Unknown` contains new variants that have been added since this code was generated.
60    #[deprecated(note = "Don't directly match on `Unknown`. See the docs on this enum for the correct way to handle unknown variants.")]
61    Unknown(crate::primitives::sealed_enum_unknown::UnknownVariantValue),
62}
63impl ::std::convert::From<&str> for SortOrder {
64    fn from(s: &str) -> Self {
65        match s {
66            "asc" => SortOrder::Asc,
67            "dsc" => SortOrder::Dsc,
68            other => SortOrder::Unknown(crate::primitives::sealed_enum_unknown::UnknownVariantValue(other.to_owned())),
69        }
70    }
71}
72impl ::std::str::FromStr for SortOrder {
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(SortOrder::from(s))
77    }
78}
79impl SortOrder {
80    /// Returns the `&str` value of the enum member.
81    pub fn as_str(&self) -> &str {
82        match self {
83            SortOrder::Asc => "asc",
84            SortOrder::Dsc => "dsc",
85            SortOrder::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        &["asc", "dsc"]
91    }
92}
93impl ::std::convert::AsRef<str> for SortOrder {
94    fn as_ref(&self) -> &str {
95        self.as_str()
96    }
97}
98impl SortOrder {
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 SortOrder {
111    fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
112        match self {
113            SortOrder::Asc => write!(f, "asc"),
114            SortOrder::Dsc => write!(f, "dsc"),
115            SortOrder::Unknown(value) => write!(f, "{}", value),
116        }
117    }
118}