summaryrefslogtreecommitdiff
path: root/src/data/modloader.rs
diff options
context:
space:
mode:
authorfxqnlr <[email protected]>2024-09-04 17:32:19 +0200
committerfxqnlr <[email protected]>2024-09-04 17:32:19 +0200
commitecc4743fdec43eb578e9c35bb008c68909f1517e (patch)
tree73916114bc2bff8c72f759f5aae11a95d4dede22 /src/data/modloader.rs
parent11e64fc7560de3cd0def718edf68c31e3dc8be72 (diff)
downloadmodlist-ecc4743fdec43eb578e9c35bb008c68909f1517e.tar
modlist-ecc4743fdec43eb578e9c35bb008c68909f1517e.tar.gz
modlist-ecc4743fdec43eb578e9c35bb008c68909f1517e.zip
better error handlingrefactor
Diffstat (limited to 'src/data/modloader.rs')
-rw-r--r--src/data/modloader.rs14
1 files changed, 6 insertions, 8 deletions
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;
2 2
3use serde::{Deserialize, Serialize}; 3use serde::{Deserialize, Serialize};
4 4
5use crate::error::{EType, MLErr, MLE}; 5use crate::errors::ConversionError;
6 6
7#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] 7#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
8pub enum Modloader { 8pub enum Modloader {
@@ -14,16 +14,14 @@ pub enum Modloader {
14 Quilt, 14 Quilt,
15} 15}
16 16
17impl Modloader { 17impl TryFrom<&str> for Modloader {
18 /// # Errors 18 type Error = ConversionError;
19 pub fn from(string: &str) -> MLE<Modloader> { 19 fn try_from(value: &str) -> Result<Self, Self::Error> {
20 match string { 20 match value {
21 "forge" => Ok(Modloader::Forge), 21 "forge" => Ok(Modloader::Forge),
22 "fabric" => Ok(Modloader::Fabric), 22 "fabric" => Ok(Modloader::Fabric),
23 "quilt" => Ok(Modloader::Quilt), 23 "quilt" => Ok(Modloader::Quilt),
24 _ => { 24 _ => Err(ConversionError::Modloader(value.to_string()))
25 Err(MLErr::new(EType::ArgumentError, "UNKNOWN_MODLOADER"))
26 }
27 } 25 }
28 } 26 }
29} 27}