From 54318b90b36e453fdf494af61035d346d8652251 Mon Sep 17 00:00:00 2001 From: TOwInOK <60252419+TOwInOK@users.noreply.github.com> Date: Sat, 4 May 2024 02:51:46 +0700 Subject: [PATCH] make download fns more arced :) --- .vscode/settings.json | 1 + settings.toml | 1 - src/main.rs | 20 ++++++++++++-------- src/settings/core.rs | 2 +- src/settings/extensions/plugins.rs | 6 +++--- 5 files changed, 17 insertions(+), 13 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index cd57afe..d2372cf 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,6 +3,7 @@ "cSpell.words": [ "парсинга", "Bukkit", + "clippy", "cooldown", "Datapack", "Datapacks", diff --git a/settings.toml b/settings.toml index 721b0fb..e61c404 100644 --- a/settings.toml +++ b/settings.toml @@ -1,7 +1,6 @@ [core] provider = "paper" version = "1.20.6" -force_update = true [plugins.simple-voice-chat] [plugins.chunky] diff --git a/src/main.rs b/src/main.rs index ea77a52..9f2b4d4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -41,21 +41,25 @@ async fn download( lock: Arc>, mpb: Arc, ) -> Result<()> { - '_download_plugins: { + '_core_scope: { + let lock = Arc::clone(&lock); + let mpb = Arc::clone(&mpb); + settings.core().download(lock, mpb).await?; + } + '_plugins_scope: { + let lock = Arc::clone(&lock); + let mpb = Arc::clone(&mpb); if let Some(plugins) = settings.plugins() { plugins .download_all( - &settings.core().provider().as_str(), - &settings.core().version(), - &lock, - &mpb, + settings.core().provider().as_str(), + settings.core().version(), + lock, + mpb, ) .await?; } } - '_download_core: { - settings.core().download(&lock, &mpb).await?; - } Ok(()) } diff --git a/src/settings/core.rs b/src/settings/core.rs index 3eb97ec..46fd3c8 100644 --- a/src/settings/core.rs +++ b/src/settings/core.rs @@ -88,7 +88,7 @@ impl Core { self.force_update = force_update; } /// Скачиваем `Core` и сохраняем его по стандартному пути. - pub async fn download(&self, lock: &Arc>, mpb: &Arc) -> Result<()> { + pub async fn download(&self, lock: Arc>, mpb: Arc) -> Result<()> { let pb = mpb.add(ProgressBar::new_spinner()); pb.set_style( ProgressStyle::with_template( diff --git a/src/settings/extensions/plugins.rs b/src/settings/extensions/plugins.rs index 46fccac..619b73c 100644 --- a/src/settings/extensions/plugins.rs +++ b/src/settings/extensions/plugins.rs @@ -32,8 +32,8 @@ impl Plugins { &self, loader: &str, game_version: &str, - lock: &Arc>, - mpb: &Arc, + lock: Arc>, + mpb: Arc, ) -> Result<()> { let mut link_list = Vec::new(); let mut handler_list: Vec>> = Vec::new(); @@ -65,7 +65,7 @@ impl Plugins { } // Make handler_list for (link, hash, build, name, pb) in link_list { - let lock = Arc::clone(lock); + let lock = Arc::clone(&lock); handler_list.push(tokio::spawn(async move { // get lock