use std::fmt::Display;
use std::str::FromStr;
use serde::{Deserialize, Serialize};
#[derive(PartialEq, Eq, Hash, Serialize, Deserialize, Debug, Clone, Copy)]
#[serde(rename_all = "lowercase")]
pub enum Platform {
Pc,
Xbox,
PlayStation,
}
impl FromStr for Platform {
type Err = ();
fn from_str(input: &str) -> Result<Platform, Self::Err> {
match input {
"pc" => Ok(Platform::Pc),
"xbox" => Ok(Platform::Xbox),
"playstation" => Ok(Platform::PlayStation),
_ => Err(()),
}
}
}
impl Display for Platform {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Platform::Pc => write!(f, "pc"),
Platform::Xbox => write!(f, "xbox"),
Platform::PlayStation => write!(f, "playstation"),
}
}
}