From ecc4743fdec43eb578e9c35bb008c68909f1517e Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Wed, 4 Sep 2024 17:32:19 +0200 Subject: better error handling --- src/data/modloader.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'src/data/modloader.rs') diff --git a/src/data/modloader.rs b/src/data/modloader.rs index 050213f..ef2611b 100644 --- a/src/data/modloader.rs +++ b/src/data/modloader.rs @@ -2,7 +2,7 @@ use std::fmt::Display; use serde::{Deserialize, Serialize}; -use crate::error::{EType, MLErr, MLE}; +use crate::errors::ConversionError; #[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub enum Modloader { @@ -14,16 +14,14 @@ pub enum Modloader { Quilt, } -impl Modloader { - /// # Errors - pub fn from(string: &str) -> MLE { - match string { +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(MLErr::new(EType::ArgumentError, "UNKNOWN_MODLOADER")) - } + _ => Err(ConversionError::Modloader(value.to_string())) } } } -- cgit v1.2.3