From a58e6fb76d84a3f2347d0008cfe3d2fb24cf2b53 Mon Sep 17 00:00:00 2001 From: objz Date: Tue, 16 Jun 2026 09:58:34 +0200 Subject: [PATCH] style: apply rustfmt --- src/instance/content/mod.rs | 8 ++-- src/instance/content/mods.rs | 3 +- src/instance/content/shaders.rs | 1 - src/instance/content/worlds.rs | 1 - src/instance/import/mod.rs | 17 ++----- src/instance/launch/patches.rs | 9 +++- src/instance/manager.rs | 4 +- src/instance/mod.rs | 7 +-- src/instance/screenshots.rs | 1 - src/launch_profile/rules.rs | 5 +- src/launch_profile/templates.rs | 10 +++- src/migrate.rs | 6 ++- src/net/fabric.rs | 3 +- src/net/mod.rs | 1 - src/tui/widgets/content/list.rs | 38 ++++++--------- src/tui/widgets/content/tabs.rs | 48 +++++++++++++++---- src/tui/widgets/mod.rs | 2 +- src/tui/widgets/popups/new_instance/render.rs | 7 +-- src/tui/widgets/settings.rs | 15 ++++-- tests/net_mojang.rs | 11 +++-- 20 files changed, 114 insertions(+), 83 deletions(-) diff --git a/src/instance/content/mod.rs b/src/instance/content/mod.rs index f2e1dd1..6b66eb7 100644 --- a/src/instance/content/mod.rs +++ b/src/instance/content/mod.rs @@ -6,11 +6,11 @@ pub mod resource_packs; pub mod shaders; pub mod worlds; -pub use mods::{ContentEntry, scan_mods, toggle_entry}; pub use mods::scan_one_mod; -pub use resource_packs::{scan_resource_packs, scan_one_resource_pack}; -pub use shaders::{scan_shaders, scan_one_shader}; -pub use worlds::{scan_worlds, scan_one_world}; +pub use mods::{ContentEntry, scan_mods, toggle_entry}; +pub use resource_packs::{scan_one_resource_pack, scan_resource_packs}; +pub use shaders::{scan_one_shader, scan_shaders}; +pub use worlds::{scan_one_world, scan_worlds}; use std::io::Read; diff --git a/src/instance/content/mods.rs b/src/instance/content/mods.rs index c7947d5..79eae93 100644 --- a/src/instance/content/mods.rs +++ b/src/instance/content/mods.rs @@ -742,7 +742,8 @@ description = "A neoforge mod" fn scan_mods_prefers_neoforge_toml_over_forge_toml() { let tmp = tempfile::tempdir().unwrap(); let dir = setup_mods_dir(tmp.path(), "inst"); - let neoforge = "[[mods]]\ndisplayName = \"NeoForge Name\"\ndescription = \"neoforge desc\"\n"; + let neoforge = + "[[mods]]\ndisplayName = \"NeoForge Name\"\ndescription = \"neoforge desc\"\n"; let forge = "[[mods]]\ndisplayName = \"Forge Name\"\ndescription = \"forge desc\"\n"; make_jar( &dir, diff --git a/src/instance/content/shaders.rs b/src/instance/content/shaders.rs index 775f8d7..0492085 100644 --- a/src/instance/content/shaders.rs +++ b/src/instance/content/shaders.rs @@ -89,4 +89,3 @@ fn read_shader_metadata_from_dir(dir: &Path) -> (String, Option>) { (description, icon_bytes) } - diff --git a/src/instance/content/worlds.rs b/src/instance/content/worlds.rs index fce0aa9..eff69be 100644 --- a/src/instance/content/worlds.rs +++ b/src/instance/content/worlds.rs @@ -134,4 +134,3 @@ fn format_size(bytes: u64) -> String { format!("{:.2} GB", bytes as f64 / (1024.0 * 1024.0 * 1024.0)) } } - diff --git a/src/instance/import/mod.rs b/src/instance/import/mod.rs index d64ff73..84e852c 100644 --- a/src/instance/import/mod.rs +++ b/src/instance/import/mod.rs @@ -154,11 +154,7 @@ mod tests { #[test] fn detect_format_recognises_mrpack() { let tmp = tempfile::tempdir().unwrap(); - let path = make_pack_zip( - tmp.path(), - "pack.mrpack", - &[("modrinth.index.json", b"{}")], - ); + let path = make_pack_zip(tmp.path(), "pack.mrpack", &[("modrinth.index.json", b"{}")]); assert_eq!(detect_format(&path), Ok(PackFormat::Mrpack)); } @@ -176,11 +172,7 @@ mod tests { // mmc-pack.json one directory deep - the more common layout where // the archive wraps everything in a named directory. let tmp = tempfile::tempdir().unwrap(); - let path = make_pack_zip( - tmp.path(), - "pack.zip", - &[("MyPack/mmc-pack.json", b"{}")], - ); + let path = make_pack_zip(tmp.path(), "pack.zip", &[("MyPack/mmc-pack.json", b"{}")]); assert_eq!(detect_format(&path), Ok(PackFormat::Mmc)); } @@ -192,10 +184,7 @@ mod tests { let path = make_pack_zip( tmp.path(), "weird.zip", - &[ - ("modrinth.index.json", b"{}"), - ("mmc-pack.json", b"{}"), - ], + &[("modrinth.index.json", b"{}"), ("mmc-pack.json", b"{}")], ); assert_eq!(detect_format(&path), Ok(PackFormat::Mrpack)); } diff --git a/src/instance/launch/patches.rs b/src/instance/launch/patches.rs index 882b44f..52f40df 100644 --- a/src/instance/launch/patches.rs +++ b/src/instance/launch/patches.rs @@ -383,8 +383,13 @@ mod tests { #[test] fn parse_add_opens_extracts_module_args() { let tmp = tempfile::tempdir().unwrap(); - let manifest = b"Manifest-Version: 1.0\nAdd-Opens: java.base/java.lang java.base/java.util\n"; - let zip_path = make_zip(tmp.path(), "patches.zip", &[("META-INF/MANIFEST.MF", manifest)]); + let manifest = + b"Manifest-Version: 1.0\nAdd-Opens: java.base/java.lang java.base/java.util\n"; + let zip_path = make_zip( + tmp.path(), + "patches.zip", + &[("META-INF/MANIFEST.MF", manifest)], + ); let args = parse_add_opens(&zip_path).expect("parsed"); assert_eq!( args, diff --git a/src/instance/manager.rs b/src/instance/manager.rs index 845d193..eec241a 100644 --- a/src/instance/manager.rs +++ b/src/instance/manager.rs @@ -468,7 +468,9 @@ mod tests { manager.touch_last_played("ticker").expect("touch"); let reloaded = manager.load_one("ticker").unwrap(); - let stamp = reloaded.last_played.expect("last_played should be Some now"); + let stamp = reloaded + .last_played + .expect("last_played should be Some now"); let age = chrono::Utc::now() - stamp; assert!( age.num_seconds().abs() < 5, diff --git a/src/instance/mod.rs b/src/instance/mod.rs index 3f30bee..7fc324f 100644 --- a/src/instance/mod.rs +++ b/src/instance/mod.rs @@ -11,11 +11,8 @@ pub mod models; pub mod screenshots; pub use content::{ - ContentEntry, toggle_entry, - scan_mods, scan_one_mod, - scan_resource_packs, scan_one_resource_pack, - scan_shaders, scan_one_shader, - scan_worlds, scan_one_world, + ContentEntry, scan_mods, scan_one_mod, scan_one_resource_pack, scan_one_shader, scan_one_world, + scan_resource_packs, scan_shaders, scan_worlds, toggle_entry, }; pub use launch::LaunchError; pub use loader::{GameVersion, ModLoaderInstaller, VanillaInstaller, get_installer}; diff --git a/src/instance/screenshots.rs b/src/instance/screenshots.rs index 62b5acd..044a247 100644 --- a/src/instance/screenshots.rs +++ b/src/instance/screenshots.rs @@ -45,4 +45,3 @@ pub fn scan_screenshots(instances_dir: &Path, instance_name: &str) -> Vec bool { fn features_match(required: &FeatureSet, current: &FeatureSet) -> bool { let pairs = [ (required.is_demo_user, current.is_demo_user), - (required.has_custom_resolution, current.has_custom_resolution), + ( + required.has_custom_resolution, + current.has_custom_resolution, + ), ( required.has_quick_plays_support, current.has_quick_plays_support, diff --git a/src/launch_profile/templates.rs b/src/launch_profile/templates.rs index b535315..3eb0e6c 100644 --- a/src/launch_profile/templates.rs +++ b/src/launch_profile/templates.rs @@ -165,7 +165,10 @@ mod tests { #[case::unclosed_placeholder("--prefix ${unclosed", "--prefix ${unclosed")] #[case::dollar_without_brace("$$ literal $5 $", "$$ literal $5 $")] #[case::multiple("${version_name}-${auth_player_name}", "1.20.1-Player")] - #[case::path("-DlibraryDirectory=${library_directory}", "-DlibraryDirectory=/m/libraries")] + #[case::path( + "-DlibraryDirectory=${library_directory}", + "-DlibraryDirectory=/m/libraries" + )] #[case::empty_input("", "")] fn substitute_handles(#[case] input: &str, #[case] expected: &str) { let fx = Fixture::unix(); @@ -178,7 +181,10 @@ mod tests { // pattern. it should NOT trigger another substitution pass. let mut fx = Fixture::unix(); fx.user_properties = "${version_name}".to_string(); - assert_eq!(substitute("${user_properties}", &fx.ctx()), "${version_name}"); + assert_eq!( + substitute("${user_properties}", &fx.ctx()), + "${version_name}" + ); } #[test] diff --git a/src/migrate.rs b/src/migrate.rs index 8b23810..b23b647 100644 --- a/src/migrate.rs +++ b/src/migrate.rs @@ -39,7 +39,11 @@ fn rename_top_level(old: &Path, new: &Path) { return; } match fs::rename(old, new) { - Ok(_) => eprintln!("rmcl migration: moved {} -> {}", old.display(), new.display()), + Ok(_) => eprintln!( + "rmcl migration: moved {} -> {}", + old.display(), + new.display() + ), Err(e) if e.kind() == io::ErrorKind::CrossesDevices => { if let Err(e2) = copy_dir_recursive(old, new) { eprintln!( diff --git a/src/net/fabric.rs b/src/net/fabric.rs index c5e4e80..d2d575b 100644 --- a/src/net/fabric.rs +++ b/src/net/fabric.rs @@ -113,8 +113,7 @@ pub async fn fetch_fabric_profile_with_raw( game_version: &str, loader_version: &str, ) -> Result<(FabricProfile, Vec), NetError> { - fetch_fabric_profile_with_raw_from(client, FABRIC_META_BASE, game_version, loader_version) - .await + fetch_fabric_profile_with_raw_from(client, FABRIC_META_BASE, game_version, loader_version).await } pub async fn fetch_fabric_profile_with_raw_from( diff --git a/src/net/mod.rs b/src/net/mod.rs index ee14103..a3b4117 100644 --- a/src/net/mod.rs +++ b/src/net/mod.rs @@ -297,5 +297,4 @@ mod tests { fn maven_empty_string() { assert_eq!(maven_coord_to_path(""), None); } - } diff --git a/src/tui/widgets/content/list.rs b/src/tui/widgets/content/list.rs index 6bd214c..9c387b4 100644 --- a/src/tui/widgets/content/list.rs +++ b/src/tui/widgets/content/list.rs @@ -92,9 +92,7 @@ impl ContentListState { received = true; let pos = self .entries - .binary_search_by(|e| { - e.name.to_lowercase().cmp(&entry.name.to_lowercase()) - }) + .binary_search_by(|e| e.name.to_lowercase().cmp(&entry.name.to_lowercase())) .unwrap_or_else(|i| i); self.entries.insert(pos, entry); } @@ -160,8 +158,7 @@ impl ContentListState { if self.entries.is_empty() { self.list_state.selected = None; } else { - self.list_state.selected = - Some(sel.min(self.entries.len().saturating_sub(1))); + self.list_state.selected = Some(sel.min(self.entries.len().saturating_sub(1))); } } @@ -235,11 +232,7 @@ impl ContentListState { for (stem, (old_path, old_enabled)) in known_map.iter() { if let Some((disk_path, disk_enabled)) = on_disk.get(stem) { if *disk_enabled != *old_enabled || *disk_path != *old_path { - toggled.push(( - stem.clone(), - *disk_enabled, - disk_path.clone(), - )); + toggled.push((stem.clone(), *disk_enabled, disk_path.clone())); } } else { removed.push(stem.clone()); @@ -366,16 +359,16 @@ impl ContentListState { continue; }; - let (enabled, file_stem) = - if let Some(stem) = fname.strip_suffix(&disabled_ext) { - (false, stem.to_owned()) - } else if let Some(stem) = fname.strip_suffix(ext) { - (true, stem.to_owned()) - } else if path.is_dir() { - crate::instance::content::parse_enabled_stem_dir(fname) - } else { - continue; - }; + let (enabled, file_stem) = if let Some(stem) = fname.strip_suffix(&disabled_ext) + { + (false, stem.to_owned()) + } else if let Some(stem) = fname.strip_suffix(ext) { + (true, stem.to_owned()) + } else if path.is_dir() { + crate::instance::content::parse_enabled_stem_dir(fname) + } else { + continue; + }; let entry = scan_one_fn(&path, &file_stem, enabled); if tx.send(entry).is_err() { @@ -879,10 +872,7 @@ fn icon_spans(icon_pixels: Option<&Vec>>, row: usize) -> Vec HashMap { +fn read_dir_stems(dir: &std::path::Path, ext: &str) -> HashMap { let mut map = HashMap::new(); let Ok(read_dir) = std::fs::read_dir(dir) else { return map; diff --git a/src/tui/widgets/content/tabs.rs b/src/tui/widgets/content/tabs.rs index 0ab95fa..11a6668 100644 --- a/src/tui/widgets/content/tabs.rs +++ b/src/tui/widgets/content/tabs.rs @@ -215,8 +215,16 @@ pub fn render( ContentTab::Mods => { if let Some(instance) = instance { if mods_state.loaded_for.as_deref() != Some(instance.name.as_str()) { - let content_dir = instances_dir.join(&instance.name).join(".minecraft").join("mods"); - mods_state.start_load(&content_dir, &instance.name, crate::instance::scan_one_mod, ".jar"); + let content_dir = instances_dir + .join(&instance.name) + .join(".minecraft") + .join("mods"); + mods_state.start_load( + &content_dir, + &instance.name, + crate::instance::scan_one_mod, + ".jar", + ); mods_state.watch_dir(content_dir); } super::list::render( @@ -238,8 +246,16 @@ pub fn render( ContentTab::ResourcePacks => { if let Some(instance) = instance { if resource_packs_state.loaded_for.as_deref() != Some(instance.name.as_str()) { - let content_dir = instances_dir.join(&instance.name).join(".minecraft").join("resourcepacks"); - resource_packs_state.start_load(&content_dir, &instance.name, crate::instance::scan_one_resource_pack, ".zip"); + let content_dir = instances_dir + .join(&instance.name) + .join(".minecraft") + .join("resourcepacks"); + resource_packs_state.start_load( + &content_dir, + &instance.name, + crate::instance::scan_one_resource_pack, + ".zip", + ); resource_packs_state.watch_dir(content_dir); } super::list::render( @@ -261,8 +277,16 @@ pub fn render( ContentTab::Shaders => { if let Some(instance) = instance { if shaders_state.loaded_for.as_deref() != Some(instance.name.as_str()) { - let content_dir = instances_dir.join(&instance.name).join(".minecraft").join("shaderpacks"); - shaders_state.start_load(&content_dir, &instance.name, crate::instance::scan_one_shader, ".zip"); + let content_dir = instances_dir + .join(&instance.name) + .join(".minecraft") + .join("shaderpacks"); + shaders_state.start_load( + &content_dir, + &instance.name, + crate::instance::scan_one_shader, + ".zip", + ); shaders_state.watch_dir(content_dir); } super::list::render( @@ -322,8 +346,16 @@ pub fn render( ContentTab::Worlds => { if let Some(instance) = instance { if worlds_state.loaded_for.as_deref() != Some(instance.name.as_str()) { - let content_dir = instances_dir.join(&instance.name).join(".minecraft").join("saves"); - worlds_state.start_load(&content_dir, &instance.name, crate::instance::scan_one_world, ""); + let content_dir = instances_dir + .join(&instance.name) + .join(".minecraft") + .join("saves"); + worlds_state.start_load( + &content_dir, + &instance.name, + crate::instance::scan_one_world, + "", + ); worlds_state.watch_dir(content_dir); } super::list::render( diff --git a/src/tui/widgets/mod.rs b/src/tui/widgets/mod.rs index 563f839..80d2694 100644 --- a/src/tui/widgets/mod.rs +++ b/src/tui/widgets/mod.rs @@ -9,12 +9,12 @@ use ratatui::{ pub mod account; pub mod content; -pub mod settings; pub mod instances; pub mod logs_viewer; pub mod popups; pub mod screenshots_grid; pub mod search; +pub mod settings; pub mod status; // highlight the first character of a title with the accent color, diff --git a/src/tui/widgets/popups/new_instance/render.rs b/src/tui/widgets/popups/new_instance/render.rs index 70a657a..5098bfc 100644 --- a/src/tui/widgets/popups/new_instance/render.rs +++ b/src/tui/widgets/popups/new_instance/render.rs @@ -426,11 +426,8 @@ mod tests { id: "1.20.1".into(), stable: true, }]); - guard.loader_versions = LoadState::Loaded(vec![ - "47.2.0".into(), - "47.1.0".into(), - "47.0.50".into(), - ]); + guard.loader_versions = + LoadState::Loaded(vec!["47.2.0".into(), "47.1.0".into(), "47.0.50".into()]); } let backend = TestBackend::new(60, 14); diff --git a/src/tui/widgets/settings.rs b/src/tui/widgets/settings.rs index afac60d..a640675 100644 --- a/src/tui/widgets/settings.rs +++ b/src/tui/widgets/settings.rs @@ -9,7 +9,10 @@ use ratatui::{ widgets::{Block, Borders, Paragraph}, }; -use crate::config::{SETTINGS, theme::{BORDER_STYLE, THEME}}; +use crate::config::{ + SETTINGS, + theme::{BORDER_STYLE, THEME}, +}; use crate::instance::models::InstanceConfig; use crate::tui::app::FocusedArea; @@ -66,8 +69,14 @@ pub fn render( .add_modifier(Modifier::BOLD); let dim_style = Style::default().fg(theme.text_dim()); - let memory_min = inst.memory_min.as_deref().unwrap_or(&SETTINGS.defaults.memory_min); - let memory_max = inst.memory_max.as_deref().unwrap_or(&SETTINGS.defaults.memory_max); + let memory_min = inst + .memory_min + .as_deref() + .unwrap_or(&SETTINGS.defaults.memory_min); + let memory_max = inst + .memory_max + .as_deref() + .unwrap_or(&SETTINGS.defaults.memory_max); let java_path = inst .java_path .as_deref() diff --git a/tests/net_mojang.rs b/tests/net_mojang.rs index a31ad6e..e4e0289 100644 --- a/tests/net_mojang.rs +++ b/tests/net_mojang.rs @@ -10,7 +10,7 @@ use wiremock::{Mock, MockServer, ResponseTemplate}; use rmcl::net::HttpClient; use rmcl::net::mojang::{ - AssetIndex, Artifact, Download, JavaVersion, Library, LibraryDownloads, VersionDownloads, + Artifact, AssetIndex, Download, JavaVersion, Library, LibraryDownloads, VersionDownloads, VersionEntry, VersionMeta, download_assets, download_assets_from, download_libraries, fetch_version_manifest_from, fetch_version_meta_with_raw, }; @@ -226,9 +226,7 @@ async fn download_assets_from_writes_index_and_assets() { .await; // asset hash starts with "ab" so the per-asset URL is //ab/. Mock::given(method("GET")) - .and(path( - "/cdn/ab/ab1234567890abcdef1234567890abcdef123456", - )) + .and(path("/cdn/ab/ab1234567890abcdef1234567890abcdef123456")) .respond_with(ResponseTemplate::new(200).set_body_bytes(b"asset-bytes".to_vec())) .expect(1) .mount(&server) @@ -272,7 +270,10 @@ async fn download_assets_writes_index_when_objects_is_empty() { .expect("download_assets index-only"); let index_path = tmp.path().join("assets/indexes/5.json"); - assert!(index_path.exists(), "expected asset index at {index_path:?}"); + assert!( + index_path.exists(), + "expected asset index at {index_path:?}" + ); let body: serde_json::Value = serde_json::from_slice(&std::fs::read(&index_path).unwrap()).unwrap(); assert!(body.get("objects").is_some());