summaryrefslogblamecommitdiff
path: root/src/data/modloader.rs
blob: 050213f84cc16fa062f209b4d33052369430bd49 (plain) (tree)






































                                                                          
use std::fmt::Display;

use serde::{Deserialize, Serialize};

use crate::error::{EType, MLErr, MLE};

#[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 Modloader {
    /// # Errors
    pub fn from(string: &str) -> MLE<Modloader> {
        match string {
            "forge" => Ok(Modloader::Forge),
            "fabric" => Ok(Modloader::Fabric),
            "quilt" => Ok(Modloader::Quilt),
            _ => {
                Err(MLErr::new(EType::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"),
            Modloader::Quilt => write!(f, "quilt"),
        }
    }
}