diff options
author | fxqnlr <[email protected]> | 2024-09-04 17:32:19 +0200 |
---|---|---|
committer | fxqnlr <[email protected]> | 2024-09-04 17:32:19 +0200 |
commit | ecc4743fdec43eb578e9c35bb008c68909f1517e (patch) | |
tree | 73916114bc2bff8c72f759f5aae11a95d4dede22 /src/data/modloader.rs | |
parent | 11e64fc7560de3cd0def718edf68c31e3dc8be72 (diff) | |
download | modlist-refactor.tar modlist-refactor.tar.gz modlist-refactor.zip |
better error handlingrefactor
Diffstat (limited to 'src/data/modloader.rs')
-rw-r--r-- | src/data/modloader.rs | 14 |
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 | ||
3 | use serde::{Deserialize, Serialize}; | 3 | use serde::{Deserialize, Serialize}; |
4 | 4 | ||
5 | use crate::error::{EType, MLErr, MLE}; | 5 | use crate::errors::ConversionError; |
6 | 6 | ||
7 | #[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] | 7 | #[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] |
8 | pub enum Modloader { | 8 | pub enum Modloader { |
@@ -14,16 +14,14 @@ pub enum Modloader { | |||
14 | Quilt, | 14 | Quilt, |
15 | } | 15 | } |
16 | 16 | ||
17 | impl Modloader { | 17 | impl 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 | } |