use super::*;
#[derive(Clone, Copy, Debug, PartialEq, SerializeDisplay, DeserializeFromStr)]
#[cfg_attr(feature = "iterator", derive(enum_iterator::Sequence))]
#[non_exhaustive]
pub enum AzureRegion {
EastUs,
EastUs2,
WestUs,
WestUs2,
}
impl CloudLocation for AzureRegion {
const CLOUD_VENDOR: &'static str = "Azure";
const CLOUD_VENDOR_PREFIX: &'static str = "azure/";
fn as_str(&self) -> &'static str {
match self {
Self::EastUs => "eastus",
Self::EastUs2 => "eastus2",
Self::WestUs => "westus",
Self::WestUs2 => "westus2",
}
}
}
impl FromStr for AzureRegion {
type Err = InvalidRegion;
fn from_str(text: &str) -> Result<Self, Self::Err> {
match Self::normal_region(text).as_str() {
"eastus" => Ok(Self::EastUs),
"eastus2" => Ok(Self::EastUs2),
"westus" => Ok(Self::WestUs),
"westus2" => Ok(Self::WestUs2),
_ => Err(InvalidRegion::new(text)),
}
}
}
impl fmt::Display for AzureRegion {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if f.alternate() {
f.write_fmt(format_args!(
"{}{}",
Self::CLOUD_VENDOR_PREFIX,
self.as_str()
))
} else {
self.as_str().fmt(f)
}
}
}
#[cfg(feature = "jsonschema")]
impl schemars::JsonSchema for AzureRegion {
fn schema_name() -> String {
"AzureRegion".to_string()
}
fn json_schema(_gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {
let enum_values = enum_iterator::all::<Self>()
.flat_map(|region| [format!("{region}"), format!("{region:#}")])
.map(Into::into)
.collect();
let instance_type = schemars::schema::InstanceType::String.into();
let object = schemars::schema::SchemaObject {
instance_type: Some(instance_type),
enum_values: Some(enum_values),
..schemars::schema::SchemaObject::default()
};
object.into()
}
}