Skip to main content

nominal_api/conjure/objects/api/
granularity.rs

1#![allow(deprecated)]
2use std::fmt;
3use std::str;
4#[derive(
5    Debug,
6    Clone,
7    PartialEq,
8    Eq,
9    PartialOrd,
10    Ord,
11    Hash,
12    conjure_object::serde::Deserialize,
13    conjure_object::serde::Serialize,
14)]
15#[serde(crate = "conjure_object::serde")]
16pub enum Granularity {
17    #[serde(rename = "NANOSECONDS")]
18    Nanoseconds,
19    /// An unknown variant.
20    #[serde(untagged)]
21    Unknown(Unknown),
22}
23impl Granularity {
24    /// Returns the string representation of the enum.
25    #[inline]
26    pub fn as_str(&self) -> &str {
27        match self {
28            Granularity::Nanoseconds => "NANOSECONDS",
29            Granularity::Unknown(v) => &*v,
30        }
31    }
32}
33impl fmt::Display for Granularity {
34    fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
35        fmt::Display::fmt(self.as_str(), fmt)
36    }
37}
38impl conjure_object::Plain for Granularity {
39    fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
40        conjure_object::Plain::fmt(self.as_str(), fmt)
41    }
42}
43impl str::FromStr for Granularity {
44    type Err = conjure_object::plain::ParseEnumError;
45    #[inline]
46    fn from_str(v: &str) -> Result<Granularity, conjure_object::plain::ParseEnumError> {
47        match v {
48            "NANOSECONDS" => Ok(Granularity::Nanoseconds),
49            v => v.parse().map(|v| Granularity::Unknown(Unknown(v))),
50        }
51    }
52}
53impl conjure_object::FromPlain for Granularity {
54    type Err = conjure_object::plain::ParseEnumError;
55    #[inline]
56    fn from_plain(
57        v: &str,
58    ) -> Result<Granularity, conjure_object::plain::ParseEnumError> {
59        v.parse()
60    }
61}
62///An unknown variant of the Granularity enum.
63#[derive(
64    Debug,
65    Clone,
66    PartialEq,
67    Eq,
68    PartialOrd,
69    Ord,
70    Hash,
71    conjure_object::serde::Deserialize,
72    conjure_object::serde::Serialize,
73)]
74#[serde(crate = "conjure_object::serde", transparent)]
75pub struct Unknown(conjure_object::private::Variant);
76impl std::ops::Deref for Unknown {
77    type Target = str;
78    #[inline]
79    fn deref(&self) -> &str {
80        &self.0
81    }
82}
83impl fmt::Display for Unknown {
84    #[inline]
85    fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
86        fmt::Display::fmt(&self.0, fmt)
87    }
88}