use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum View {
Bay,
Beach,
Bridges,
Canal,
Canyon,
City,
CityLights,
CreekStream,
Desert,
Downtown,
Forest,
Garden,
GolfCourse,
Hills,
Lake,
Marina,
Meadow,
Mountains,
Neighborhood,
None,
Ocean,
Orchard,
Other,
Panoramic,
ParkGreenbelt,
Pasture,
Pond,
Pool,
Ridge,
River,
Rural,
SeeRemarks,
Skyline,
Territorial,
TreesWoods,
Valley,
Vineyard,
Water,
OpenEnumeration(String),
}
impl crate::ResoEnumeration for View {
fn from_str(s: &str) -> View {
match s {
"Bay" => View::Bay,
"Beach" => View::Beach,
"Bridge(s)" => View::Bridges,
"Canal" => View::Canal,
"Canyon" => View::Canyon,
"City" => View::City,
"City Lights" => View::CityLights,
"Creek/Stream" => View::CreekStream,
"Desert" => View::Desert,
"Downtown" => View::Downtown,
"Forest" => View::Forest,
"Garden" => View::Garden,
"Golf Course" => View::GolfCourse,
"Hills" => View::Hills,
"Lake" => View::Lake,
"Marina" => View::Marina,
"Meadow" => View::Meadow,
"Mountain(s)" => View::Mountains,
"Neighborhood" => View::Neighborhood,
"None" => View::None,
"Ocean" => View::Ocean,
"Orchard" => View::Orchard,
"Other" => View::Other,
"Panoramic" => View::Panoramic,
"Park/Greenbelt" => View::ParkGreenbelt,
"Pasture" => View::Pasture,
"Pond" => View::Pond,
"Pool" => View::Pool,
"Ridge" => View::Ridge,
"River" => View::River,
"Rural" => View::Rural,
"See Remarks" => View::SeeRemarks,
"Skyline" => View::Skyline,
"Territorial" => View::Territorial,
"Trees/Woods" => View::TreesWoods,
"Valley" => View::Valley,
"Vineyard" => View::Vineyard,
"Water" => View::Water,
_ => View::OpenEnumeration(s.into()),
}
}
fn from_string(s: String) -> View {
match s.as_ref() {
"Bay" => View::Bay,
"Beach" => View::Beach,
"Bridge(s)" => View::Bridges,
"Canal" => View::Canal,
"Canyon" => View::Canyon,
"City" => View::City,
"City Lights" => View::CityLights,
"Creek/Stream" => View::CreekStream,
"Desert" => View::Desert,
"Downtown" => View::Downtown,
"Forest" => View::Forest,
"Garden" => View::Garden,
"Golf Course" => View::GolfCourse,
"Hills" => View::Hills,
"Lake" => View::Lake,
"Marina" => View::Marina,
"Meadow" => View::Meadow,
"Mountain(s)" => View::Mountains,
"Neighborhood" => View::Neighborhood,
"None" => View::None,
"Ocean" => View::Ocean,
"Orchard" => View::Orchard,
"Other" => View::Other,
"Panoramic" => View::Panoramic,
"Park/Greenbelt" => View::ParkGreenbelt,
"Pasture" => View::Pasture,
"Pond" => View::Pond,
"Pool" => View::Pool,
"Ridge" => View::Ridge,
"River" => View::River,
"Rural" => View::Rural,
"See Remarks" => View::SeeRemarks,
"Skyline" => View::Skyline,
"Territorial" => View::Territorial,
"Trees/Woods" => View::TreesWoods,
"Valley" => View::Valley,
"Vineyard" => View::Vineyard,
"Water" => View::Water,
_ => View::OpenEnumeration(s),
}
}
fn to_str(&self) -> &str {
match self {
View::Bay => "Bay",
View::Beach => "Beach",
View::Bridges => "Bridge(s)",
View::Canal => "Canal",
View::Canyon => "Canyon",
View::City => "City",
View::CityLights => "City Lights",
View::CreekStream => "Creek/Stream",
View::Desert => "Desert",
View::Downtown => "Downtown",
View::Forest => "Forest",
View::Garden => "Garden",
View::GolfCourse => "Golf Course",
View::Hills => "Hills",
View::Lake => "Lake",
View::Marina => "Marina",
View::Meadow => "Meadow",
View::Mountains => "Mountain(s)",
View::Neighborhood => "Neighborhood",
View::None => "None",
View::Ocean => "Ocean",
View::Orchard => "Orchard",
View::Other => "Other",
View::Panoramic => "Panoramic",
View::ParkGreenbelt => "Park/Greenbelt",
View::Pasture => "Pasture",
View::Pond => "Pond",
View::Pool => "Pool",
View::Ridge => "Ridge",
View::River => "River",
View::Rural => "Rural",
View::SeeRemarks => "See Remarks",
View::Skyline => "Skyline",
View::Territorial => "Territorial",
View::TreesWoods => "Trees/Woods",
View::Valley => "Valley",
View::Vineyard => "Vineyard",
View::Water => "Water",
View::OpenEnumeration(ref s) => s,
}
}
fn into_string(self) -> String {
match self {
View::Bay => "Bay".into(),
View::Beach => "Beach".into(),
View::Bridges => "Bridge(s)".into(),
View::Canal => "Canal".into(),
View::Canyon => "Canyon".into(),
View::City => "City".into(),
View::CityLights => "City Lights".into(),
View::CreekStream => "Creek/Stream".into(),
View::Desert => "Desert".into(),
View::Downtown => "Downtown".into(),
View::Forest => "Forest".into(),
View::Garden => "Garden".into(),
View::GolfCourse => "Golf Course".into(),
View::Hills => "Hills".into(),
View::Lake => "Lake".into(),
View::Marina => "Marina".into(),
View::Meadow => "Meadow".into(),
View::Mountains => "Mountain(s)".into(),
View::Neighborhood => "Neighborhood".into(),
View::None => "None".into(),
View::Ocean => "Ocean".into(),
View::Orchard => "Orchard".into(),
View::Other => "Other".into(),
View::Panoramic => "Panoramic".into(),
View::ParkGreenbelt => "Park/Greenbelt".into(),
View::Pasture => "Pasture".into(),
View::Pond => "Pond".into(),
View::Pool => "Pool".into(),
View::Ridge => "Ridge".into(),
View::River => "River".into(),
View::Rural => "Rural".into(),
View::SeeRemarks => "See Remarks".into(),
View::Skyline => "Skyline".into(),
View::Territorial => "Territorial".into(),
View::TreesWoods => "Trees/Woods".into(),
View::Valley => "Valley".into(),
View::Vineyard => "Vineyard".into(),
View::Water => "Water".into(),
View::OpenEnumeration(s) => s,
}
}
fn fallback_value(&self) -> Option<&str> {
match self {
View::OpenEnumeration(ref s) => Some(s),
_ => None,
}
}
}
impl From<String> for View {
fn from(s: String) -> View {
match s.as_ref() {
"Bay" => View::Bay,
"Beach" => View::Beach,
"Bridge(s)" => View::Bridges,
"Canal" => View::Canal,
"Canyon" => View::Canyon,
"City" => View::City,
"City Lights" => View::CityLights,
"Creek/Stream" => View::CreekStream,
"Desert" => View::Desert,
"Downtown" => View::Downtown,
"Forest" => View::Forest,
"Garden" => View::Garden,
"Golf Course" => View::GolfCourse,
"Hills" => View::Hills,
"Lake" => View::Lake,
"Marina" => View::Marina,
"Meadow" => View::Meadow,
"Mountain(s)" => View::Mountains,
"Neighborhood" => View::Neighborhood,
"None" => View::None,
"Ocean" => View::Ocean,
"Orchard" => View::Orchard,
"Other" => View::Other,
"Panoramic" => View::Panoramic,
"Park/Greenbelt" => View::ParkGreenbelt,
"Pasture" => View::Pasture,
"Pond" => View::Pond,
"Pool" => View::Pool,
"Ridge" => View::Ridge,
"River" => View::River,
"Rural" => View::Rural,
"See Remarks" => View::SeeRemarks,
"Skyline" => View::Skyline,
"Territorial" => View::Territorial,
"Trees/Woods" => View::TreesWoods,
"Valley" => View::Valley,
"Vineyard" => View::Vineyard,
"Water" => View::Water,
_ => View::OpenEnumeration(s),
}
}
}
impl From<&str> for View {
fn from(s: &str) -> View {
match s {
"Bay" => View::Bay,
"Beach" => View::Beach,
"Bridge(s)" => View::Bridges,
"Canal" => View::Canal,
"Canyon" => View::Canyon,
"City" => View::City,
"City Lights" => View::CityLights,
"Creek/Stream" => View::CreekStream,
"Desert" => View::Desert,
"Downtown" => View::Downtown,
"Forest" => View::Forest,
"Garden" => View::Garden,
"Golf Course" => View::GolfCourse,
"Hills" => View::Hills,
"Lake" => View::Lake,
"Marina" => View::Marina,
"Meadow" => View::Meadow,
"Mountain(s)" => View::Mountains,
"Neighborhood" => View::Neighborhood,
"None" => View::None,
"Ocean" => View::Ocean,
"Orchard" => View::Orchard,
"Other" => View::Other,
"Panoramic" => View::Panoramic,
"Park/Greenbelt" => View::ParkGreenbelt,
"Pasture" => View::Pasture,
"Pond" => View::Pond,
"Pool" => View::Pool,
"Ridge" => View::Ridge,
"River" => View::River,
"Rural" => View::Rural,
"See Remarks" => View::SeeRemarks,
"Skyline" => View::Skyline,
"Territorial" => View::Territorial,
"Trees/Woods" => View::TreesWoods,
"Valley" => View::Valley,
"Vineyard" => View::Vineyard,
"Water" => View::Water,
_ => View::OpenEnumeration(s.into()),
}
}
}
impl<'a> From<&'a View> for &'a str {
fn from(s: &'a View) -> &'a str {
match s {
View::Bay => "Bay",
View::Beach => "Beach",
View::Bridges => "Bridge(s)",
View::Canal => "Canal",
View::Canyon => "Canyon",
View::City => "City",
View::CityLights => "City Lights",
View::CreekStream => "Creek/Stream",
View::Desert => "Desert",
View::Downtown => "Downtown",
View::Forest => "Forest",
View::Garden => "Garden",
View::GolfCourse => "Golf Course",
View::Hills => "Hills",
View::Lake => "Lake",
View::Marina => "Marina",
View::Meadow => "Meadow",
View::Mountains => "Mountain(s)",
View::Neighborhood => "Neighborhood",
View::None => "None",
View::Ocean => "Ocean",
View::Orchard => "Orchard",
View::Other => "Other",
View::Panoramic => "Panoramic",
View::ParkGreenbelt => "Park/Greenbelt",
View::Pasture => "Pasture",
View::Pond => "Pond",
View::Pool => "Pool",
View::Ridge => "Ridge",
View::River => "River",
View::Rural => "Rural",
View::SeeRemarks => "See Remarks",
View::Skyline => "Skyline",
View::Territorial => "Territorial",
View::TreesWoods => "Trees/Woods",
View::Valley => "Valley",
View::Vineyard => "Vineyard",
View::Water => "Water",
View::OpenEnumeration(s) => s,
}
}
}
impl Serialize for View {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_str(self.into())
}
}
impl<'de> Deserialize<'de> for View {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let s = String::deserialize(deserializer)?;
Ok(From::from(s))
}
}