use std::fmt::Display; use serde::{Deserialize, Serialize}; use crate::errors::ConversionError; #[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub enum Modloader { #[serde(rename(serialize = "fabric", deserialize = "fabric"))] Fabric, #[serde(rename(serialize = "forge", deserialize = "forge"))] Forge, #[serde(rename(serialize = "quilt", deserialize = "quilt"))] Quilt, } impl TryFrom<&str> for Modloader { type Error = ConversionError; fn try_from(value: &str) -> Result { match value { "forge" => Ok(Modloader::Forge), "fabric" => Ok(Modloader::Fabric), "quilt" => Ok(Modloader::Quilt), _ => Err(ConversionError::Modloader(value.to_string())) } } } impl Display for Modloader { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { Modloader::Fabric => write!(f, "fabric"), Modloader::Forge => write!(f, "forge"), Modloader::Quilt => write!(f, "quilt"), } } }