Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

Commit

Permalink
remove unnecessary types in models (core, extension)
Browse files Browse the repository at this point in the history
add async_trait in traits if it possible
  • Loading branch information
TOwInOK committed May 27, 2024
1 parent d0b02dc commit e0296c1
Show file tree
Hide file tree
Showing 7 changed files with 6 additions and 19 deletions.
3 changes: 0 additions & 3 deletions src/models/cores/paper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -45,8 +44,6 @@ struct Application {
}

impl<T: ModelCorePaperFamily> 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;
Expand Down
4 changes: 0 additions & 4 deletions src/models/cores/purpur.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 0 additions & 2 deletions src/models/cores/vanilla.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 1 addition & 3 deletions src/models/extensions/modrinth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 3 additions & 1 deletion src/models/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>;
}

#[async_trait]
pub trait ModelExtensions {
async fn get_link(
name: &str,
Expand Down
4 changes: 1 addition & 3 deletions src/tr/model/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Output = Result<(Self::Link, ChooseHash, Self::Version)>> + Send;
) -> impl std::future::Future<Output = Result<(String, ChooseHash, String)>> + Send; // Link, Hash, Build
}
4 changes: 1 addition & 3 deletions src/tr/model/extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Output = Result<(Self::Link, ChooseHash, Self::Version)>> + Send;
) -> impl std::future::Future<Output = Result<(String, ChooseHash, String)>> + Send; // Link, Hash, Build
}

0 comments on commit e0296c1

Please sign in to comment.