pub mod apis; pub mod cache; pub mod commands; pub mod config; pub mod db; pub mod error; pub mod files; use std::fmt::Display; pub use apis::*; pub use commands::*; use error::{ErrorType, MLError, MLE}; use serde::{Deserialize, Serialize, de::Visitor}; #[derive(Debug, Clone, PartialEq, Eq)] pub enum Modloader { Fabric, Forge, } impl Modloader { pub fn from(string: &str) -> MLE { match string { "forge" => Ok(Modloader::Forge), "fabric" => Ok(Modloader::Fabric), _ => Err(MLError::new(ErrorType::ArgumentError, "UNKNOWN_MODLOADER")), } } } 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"), } } } impl Serialize for Modloader { fn serialize(&self, serializer: S) -> Result where S: serde::Serializer { match self { Modloader::Fabric => serializer.serialize_str("fabric"), Modloader::Forge => serializer.serialize_str("forge"), } } } impl<'de> Deserialize<'de> for Modloader { fn deserialize(deserializer: D) -> Result where D: serde::Deserializer<'de>, { struct FieldVisitor; impl<'de> Visitor<'de> for FieldVisitor { type Value = Modloader; fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { formatter.write_str("`fabric`, `forge` or `quilt`") } fn visit_str(self, v: &str) -> Result where E: serde::de::Error, { match v { "fabric" => Ok(Modloader::Fabric), "forge" => Ok(Modloader::Forge), _ => Err(serde::de::Error::unknown_field(v, &["fabric", "forge", "quilt"])) } } } deserializer.deserialize_identifier(FieldVisitor) } }