summaryrefslogtreecommitdiff
path: root/src/data/modloader.rs
blob: ef2611ba7230617ebaed6d4a0d7108ef723d8e66 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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<Self, Self::Error> {
        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"),
        }
    }
}