zesty_api/location/
azure.rs1use super::*;
7
8#[derive(Clone, Copy, Debug, PartialEq, SerializeDisplay, DeserializeFromStr)]
9#[cfg_attr(feature = "iterator", derive(enum_iterator::Sequence))]
10#[non_exhaustive]
11pub enum AzureRegion {
12 EastUs,
13 EastUs2,
14 WestUs,
15 WestUs2,
16}
17
18impl AzureRegion {
19 pub fn as_str(&self) -> &'static str {
20 match self {
21 Self::EastUs => "eastus",
22 Self::EastUs2 => "eastus2",
23 Self::WestUs => "westus",
24 Self::WestUs2 => "westus2",
25 }
26 }
27}
28
29impl CloudLocation for AzureRegion {
30 const CLOUD_VENDOR: &'static str = "Azure";
31 const CLOUD_VENDOR_PREFIX: &'static str = "azure/";
32}
33
34impl FromStr for AzureRegion {
35 type Err = InvalidRegion;
36
37 fn from_str(text: &str) -> Result<Self, Self::Err> {
38 match Self::normal_region(text).as_str() {
39 "eastus" => Ok(Self::EastUs),
40 "eastus2" => Ok(Self::EastUs2),
41 "westus" => Ok(Self::WestUs),
42 "westus2" => Ok(Self::WestUs2),
43 _ => Err(InvalidRegion::new(text)),
44 }
45 }
46}
47
48impl fmt::Display for AzureRegion {
49 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
50 if f.alternate() {
51 f.write_fmt(format_args!(
52 "{}{}",
53 Self::CLOUD_VENDOR_PREFIX,
54 self.as_str()
55 ))
56 } else {
57 self.as_str().fmt(f)
58 }
59 }
60}
61
62#[cfg(feature = "jsonschema")]
63impl schemars::JsonSchema for AzureRegion {
64 fn schema_name() -> String {
65 "AzureRegion".to_string()
66 }
67
68 fn json_schema(_gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {
69 let enum_values = enum_iterator::all::<Self>()
70 .flat_map(|region| [format!("{region}"), format!("{region:#}")])
71 .map(Into::into)
72 .collect();
73 let instance_type = schemars::schema::InstanceType::String.into();
74 let object = schemars::schema::SchemaObject {
75 instance_type: Some(instance_type),
76 enum_values: Some(enum_values),
77 ..schemars::schema::SchemaObject::default()
88 };
89 object.into()
90 }
91}