From 202ed4fcaa69e7de23e83fab0bae4ced6209eee4 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Tue, 2 May 2023 20:37:23 +0200 Subject: added config option for default mc version changed version input system --- Cargo.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Cargo.lock') diff --git a/Cargo.lock b/Cargo.lock index f25b161..0e93641 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -798,7 +798,7 @@ dependencies = [ [[package]] name = "modlist" -version = "0.13.1" +version = "0.14.0" dependencies = [ "chrono", "clap", -- cgit v1.2.3 From 245b6b9926033acd750503ab4947c9514c5e1aa6 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Wed, 3 May 2023 08:01:51 +0200 Subject: fuck serde, plus maybe added quilt --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/apis/modrinth.rs | 9 ++--- src/lib.rs | 96 ++++++---------------------------------------------- 4 files changed, 15 insertions(+), 94 deletions(-) (limited to 'Cargo.lock') diff --git a/Cargo.lock b/Cargo.lock index 0e93641..7422038 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -798,7 +798,7 @@ dependencies = [ [[package]] name = "modlist" -version = "0.14.0" +version = "0.14.1" dependencies = [ "chrono", "clap", diff --git a/Cargo.toml b/Cargo.toml index 736831d..bd41811 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "modlist" -version = "0.14.0" +version = "0.14.1" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/src/apis/modrinth.rs b/src/apis/modrinth.rs index 13e7a6d..525cc0d 100644 --- a/src/apis/modrinth.rs +++ b/src/apis/modrinth.rs @@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize}; use crate::{ error::{ErrorType, MLError, MLE}, - List, Modloader, + List, }; #[derive(Debug, Deserialize, Clone)] @@ -168,14 +168,9 @@ pub async fn projects(api: &str, ids: Vec) -> Vec { ///Get applicable versions from mod_id with list context pub async fn versions(api: &str, id: String, list: List) -> Vec { - let loaderstr = match list.modloader { - Modloader::Forge => String::from("forge"), - Modloader::Fabric => String::from("fabric"), - }; - let url = format!( r#"project/{}/version?loaders=["{}"]&game_versions=["{}"]"#, - id, loaderstr, list.mc_version + id, list.modloader.to_string(), list.mc_version ); let data = get(api, &url).await.unwrap(); diff --git a/src/lib.rs b/src/lib.rs index 73b5697..b48bf61 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,12 +12,16 @@ pub use apis::*; use apis::modrinth::{get_game_versions, GameVersion, GameVersionType}; pub use commands::*; use error::{ErrorType, MLError, MLE}; -use serde::{Deserialize, Serialize, de::Visitor}; +use serde::{Deserialize, Serialize}; -#[derive(Debug, Clone, PartialEq, Eq)] +#[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 { @@ -35,53 +39,16 @@ impl Display for Modloader { match self { Modloader::Fabric => write!(f, "fabric"), Modloader::Forge => write!(f, "forge"), + Modloader::Quilt => write!(f, "quilt"), } } } -impl Serialize for Modloader { - fn serialize(&self, serializer: S) -> Result - where - S: serde::Serializer { - match self { - Modloader::Fabric => serializer.serialize_str("fabric"), - Modloader::Forge => serializer.serialize_str("forge"), - } - } -} - -impl<'de> Deserialize<'de> for Modloader { - fn deserialize(deserializer: D) -> Result - where - D: serde::Deserializer<'de>, - { - struct FieldVisitor; - - impl<'de> Visitor<'de> for FieldVisitor { - type Value = Modloader; - - fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { - formatter.write_str("`fabric`, `forge` or `quilt`") - } - - fn visit_str(self, v: &str) -> Result - where - E: serde::de::Error, { - match v { - "fabric" => Ok(Modloader::Fabric), - "forge" => Ok(Modloader::Forge), - _ => Err(serde::de::Error::unknown_field(v, &["fabric", "forge", "quilt"])) - } - } - } - - deserializer.deserialize_identifier(FieldVisitor) - } -} - -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Deserialize, Serialize)] pub enum VersionLevel { + #[serde(rename(serialize = "release", deserialize = "release"))] Release, + #[serde(rename(serialize = "snapshot", deserialize = "snapshot"))] Snapshot, Version(String) } @@ -101,7 +68,7 @@ pub async fn check_game_versions(path: &str, force: bool) -> MLE<()> { Ok(()) } -/// Loads game versions +/// Loads game versions from file pub fn load_game_versions(path: &str) -> MLE> { let mut file = File::open(path)?; let mut data = String::new(); @@ -145,44 +112,3 @@ impl VersionLevel { } } } - -impl Serialize for VersionLevel { - fn serialize(&self, serializer: S) -> Result - where - S: serde::Serializer { - match self { - VersionLevel::Release => serializer.serialize_str("release"), - VersionLevel::Snapshot => serializer.serialize_str("snapshot"), - VersionLevel::Version(v) => serializer.serialize_str(v), - } - } -} - -impl<'de> Deserialize<'de> for VersionLevel { - fn deserialize(deserializer: D) -> Result - where - D: serde::Deserializer<'de>, - { - struct FieldVisitor; - - impl<'de> Visitor<'de> for FieldVisitor { - type Value = VersionLevel; - - fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { - formatter.write_str("`fabric`, `forge` or `quilt`") - } - - fn visit_str(self, v: &str) -> Result - where - E: serde::de::Error, { - match v { - "release" => Ok(VersionLevel::Release), - "snapshot" => Ok(VersionLevel::Snapshot), - _ => Ok(VersionLevel::Version(String::from(v))) - } - } - } - - deserializer.deserialize_identifier(FieldVisitor) - } -} -- cgit v1.2.3