From e0296c1d565ec192ef278217ec74903fd25e0c86 Mon Sep 17 00:00:00 2001 From: TOwInOK <60252419+TOwInOK@users.noreply.github.com> Date: Mon, 27 May 2024 16:45:55 +0700 Subject: [PATCH] remove unnecessary types in models (core, extension) add async_trait in traits if it possible --- src/models/cores/paper.rs | 3 --- src/models/cores/purpur.rs | 4 ---- src/models/cores/vanilla.rs | 2 -- src/models/extensions/modrinth.rs | 4 +--- src/models/model.rs | 4 +++- src/tr/model/core.rs | 4 +--- src/tr/model/extension.rs | 4 +--- 7 files changed, 6 insertions(+), 19 deletions(-) diff --git a/src/models/cores/paper.rs b/src/models/cores/paper.rs index 2150c1a..54f989e 100644 --- a/src/models/cores/paper.rs +++ b/src/models/cores/paper.rs @@ -8,7 +8,6 @@ use crate::{ tr::{hash::ChooseHash, model::core::ModelCore}, DICTIONARY, }; - pub struct Paper(); impl ModelCorePaperFamily for Paper { const CORE_NAME: &'static str = "paper"; @@ -45,8 +44,6 @@ struct Application { } impl ModelCore for T { - type Link = String; - type Version = String; //find build and push link async fn get_link(core: &Core, pb: &ProgressBar) -> Result<(String, ChooseHash, String)> { let core_name = Self::CORE_NAME; diff --git a/src/models/cores/purpur.rs b/src/models/cores/purpur.rs index 95c9e6e..cd3dac7 100644 --- a/src/models/cores/purpur.rs +++ b/src/models/cores/purpur.rs @@ -38,10 +38,6 @@ struct FileHash { const MAIN_LINK: &str = "https://api.purpurmc.org/v2/purpur"; impl ModelCore for Purpur { - type Link = String; - - type Version = String; - //find build and push link async fn get_link(core: &Core, _pb: &ProgressBar) -> Result<(String, ChooseHash, String)> { let build = core.build(); diff --git a/src/models/cores/vanilla.rs b/src/models/cores/vanilla.rs index e816f42..00e8b42 100644 --- a/src/models/cores/vanilla.rs +++ b/src/models/cores/vanilla.rs @@ -66,8 +66,6 @@ struct Server { } impl ModelCore for Vanilla { - type Link = OuterLink; - type Version = VersionID; /// Making request to mojang api and find the link to download minecraft.jar async fn get_link( core: &Core, diff --git a/src/models/extensions/modrinth.rs b/src/models/extensions/modrinth.rs index b044082..b0bc2a3 100644 --- a/src/models/extensions/modrinth.rs +++ b/src/models/extensions/modrinth.rs @@ -43,14 +43,12 @@ struct Dependency { impl ModelExtensions for ModrinthData { type Ext = Plugin; - type Link = String; - type Version = String; async fn get_link( ext: &Self::Ext, name: &str, game_version: Option<&String>, loader: &str, - ) -> Result<(Self::Link, ChooseHash, Self::Version)> { + ) -> Result<(String, ChooseHash, String)> { let channel = ext.channel().get_str().await.to_string(); let link = format!("https://api.modrinth.com/v2/project/{}/version", name); diff --git a/src/models/model.rs b/src/models/model.rs index 712b26e..14192b5 100644 --- a/src/models/model.rs +++ b/src/models/model.rs @@ -3,12 +3,14 @@ use crate::{ downloader::hash::ChooseHash, errors::error::Result, }; +use async_trait::async_trait; +#[async_trait] pub trait ModelCore { async fn get_link(core: &Core) -> Result<(String, ChooseHash, String)>; async fn find_version(version: Option<&str>) -> Result; } - +#[async_trait] pub trait ModelExtensions { async fn get_link( name: &str, diff --git a/src/tr/model/core.rs b/src/tr/model/core.rs index 21c2bc6..63d7f82 100644 --- a/src/tr/model/core.rs +++ b/src/tr/model/core.rs @@ -5,10 +5,8 @@ use crate::settings::core::Core; use crate::tr::hash::ChooseHash; pub trait ModelCore { - type Link; - type Version; fn get_link( core: &Core, mpb: &ProgressBar, - ) -> impl std::future::Future> + Send; + ) -> impl std::future::Future> + Send; // Link, Hash, Build } diff --git a/src/tr/model/extension.rs b/src/tr/model/extension.rs index e0b1318..e4e6b2b 100644 --- a/src/tr/model/extension.rs +++ b/src/tr/model/extension.rs @@ -3,12 +3,10 @@ use crate::tr::hash::ChooseHash; pub trait ModelExtensions { type Ext; - type Link; - type Version; fn get_link( ext: &Self::Ext, name: &str, game_version: Option<&String>, loader: &str, - ) -> impl std::future::Future> + Send; + ) -> impl std::future::Future> + Send; // Link, Hash, Build }