From 4cb12c318e592b12251b41fa367c34af75485ef6 Mon Sep 17 00:00:00 2001 From: Wolf Vollprecht Date: Wed, 11 Dec 2024 13:00:12 +0100 Subject: [PATCH] fmt clippy --- crates/rattler_menuinst/src/linux/menu_xml.rs | 45 +++++++++++-------- crates/rattler_menuinst/src/windows.rs | 2 +- .../src/windows/create_shortcut.rs | 19 +++----- 3 files changed, 33 insertions(+), 33 deletions(-) diff --git a/crates/rattler_menuinst/src/linux/menu_xml.rs b/crates/rattler_menuinst/src/linux/menu_xml.rs index 712eec02c..5c2e57458 100644 --- a/crates/rattler_menuinst/src/linux/menu_xml.rs +++ b/crates/rattler_menuinst/src/linux/menu_xml.rs @@ -2,9 +2,9 @@ use chrono::Utc; use fs_err::{self as fs, File}; use quick_xml::events::Event; use quick_xml::{Reader, Writer}; -use thiserror::Error; use std::io::Write; use std::path::PathBuf; +use thiserror::Error; use crate::{slugify, MenuInstError}; @@ -56,16 +56,16 @@ impl MenuXml { self.menu_config_location.display(), self.name ); - + let contents = self.contents()?; let mut reader = Reader::from_str(&contents); reader.config_mut().trim_text(true); - + let mut writer = Writer::new_with_indent(Vec::new(), b' ', 2); let mut buf = Vec::new(); let mut skip_menu = false; let mut depth = 0; - + loop { match reader.read_event_into(&mut buf)? { Event::Start(e) => { @@ -103,10 +103,10 @@ impl MenuXml { } buf.clear(); } - + self.write_menu_file(&writer.into_inner()) } - + pub fn has_menu(&self) -> Result { let contents = self.contents()?; let mut reader = Reader::from_str(&contents); @@ -163,9 +163,11 @@ impl MenuXml { let mut reader = reader; loop { match reader.read_event_into(&mut buf) { - Ok(Event::Start(e)) => if e.name().as_ref() == b"Menu" { - return true; - }, + Ok(Event::Start(e)) => { + if e.name().as_ref() == b"Menu" { + return true; + } + } Ok(Event::Eof) => break, _ => (), } @@ -231,7 +233,13 @@ fn main() { let menu_config = PathBuf::from("applications.menu"); let system_menu_config = PathBuf::from("system_applications.menu"); - let menu_xml = MenuXml::new(menu_config, system_menu_config, "Test Menu".to_string(), "user".to_string()).unwrap(); + let menu_xml = MenuXml::new( + menu_config, + system_menu_config, + "Test Menu".to_string(), + "user".to_string(), + ) + .unwrap(); menu_xml.ensure_menu_file().unwrap(); if menu_xml.has_menu().unwrap() { @@ -258,7 +266,8 @@ mod tests { system_menu_config, "Test Menu".to_string(), "user".to_string(), - ).unwrap(); + ) + .unwrap(); (temp_dir, menu_xml) } @@ -325,7 +334,7 @@ mod tests { #[test] fn test_remove_menu_xml_structure() { let (_temp_dir, menu_xml) = setup_test_dir(); - + // Create initial menu file with content let initial_content = r#" @@ -340,23 +349,23 @@ mod tests { "#; - + fs::write(&menu_xml.menu_config_location, initial_content).unwrap(); - + // Remove the menu menu_xml.remove_menu().unwrap(); - + // Read and verify the result let result = fs::read_to_string(&menu_xml.menu_config_location).unwrap(); - + insta::assert_snapshot!(result); } - + #[test] // load file from test data (example.menu) and add a new entry, then remove it fn test_add_and_remove_menu_xml_structure() { let (_temp_dir, menu_xml) = setup_test_dir(); - + let test_data = test_data(); let schema_path = test_data.join("linux-menu/example.menu"); diff --git a/crates/rattler_menuinst/src/windows.rs b/crates/rattler_menuinst/src/windows.rs index 32eb2e489..3d8ff9689 100644 --- a/crates/rattler_menuinst/src/windows.rs +++ b/crates/rattler_menuinst/src/windows.rs @@ -14,9 +14,9 @@ use crate::{ use fs_err as fs; +mod create_shortcut; mod knownfolders; mod lex; -mod create_shortcut; pub struct Directories { start_menu: PathBuf, diff --git a/crates/rattler_menuinst/src/windows/create_shortcut.rs b/crates/rattler_menuinst/src/windows/create_shortcut.rs index 7ce16bb79..cb1266ac3 100644 --- a/crates/rattler_menuinst/src/windows/create_shortcut.rs +++ b/crates/rattler_menuinst/src/windows/create_shortcut.rs @@ -1,9 +1,6 @@ use windows::{ - core::*, - Win32::System::Com::*, - Win32::UI::Shell::*, - Win32::System::Com::StructuredStorage::*, - Win32::Storage::EnhancedStorage::PKEY_AppUserModel_ID, + core::*, Win32::Storage::EnhancedStorage::PKEY_AppUserModel_ID, + Win32::System::Com::StructuredStorage::*, Win32::System::Com::*, Win32::UI::Shell::*, }; use PropertiesSystem::IPropertyStore; @@ -24,11 +21,8 @@ fn create_shortcut( panic!("Failed to initialize COM"); } - let shell_link: IShellLinkW = CoCreateInstance( - &ShellLink as *const GUID, - None, - CLSCTX_INPROC_SERVER - )?; + let shell_link: IShellLinkW = + CoCreateInstance(&ShellLink as *const GUID, None, CLSCTX_INPROC_SERVER)?; // Get IPersistFile interface let persist_file: IPersistFile = shell_link.cast()?; @@ -47,10 +41,7 @@ fn create_shortcut( } if let Some(icon_path) = iconpath { - shell_link.SetIconLocation( - &HSTRING::from(icon_path), - iconindex.unwrap_or(0) - )?; + shell_link.SetIconLocation(&HSTRING::from(icon_path), iconindex.unwrap_or(0))?; } // Handle App User Model ID if provided