Improved Rust syntax by Clippy suggestions

This commit is contained in:
Thorsten Sommer 2026-05-16 18:53:18 +02:00
parent 91cfe8dcd0
commit d0fa6524af
Signed by untrusted user who does not match committer: tsommer
GPG Key ID: 371BBA77A02C0108
5 changed files with 51 additions and 67 deletions

View File

@ -245,11 +245,9 @@ fn should_open_in_system_browser<R: tauri::Runtime>(webview: &tauri::Webview<R>,
} }
} }
if let Ok(current_url) = webview.url() { if let Ok(current_url) = webview.url() && same_origin(&current_url, url) {
if same_origin(&current_url, url) {
return false; return false;
} }
}
!is_local_host(url.host_str()) !is_local_host(url.host_str())
} }
@ -415,11 +413,9 @@ pub async fn change_location_to(url: &str) {
} }
} }
if let Ok(parsed_url) = tauri::Url::parse(url) { if let Ok(parsed_url) = tauri::Url::parse(url) && is_local_http_url(&parsed_url) {
if is_local_http_url(&parsed_url) {
*APPROVED_APP_URL.lock().unwrap() = Some(parsed_url); *APPROVED_APP_URL.lock().unwrap() = Some(parsed_url);
} }
}
let js_location_change = format!("window.location = '{url}';"); let js_location_change = format!("window.location = '{url}';");
let main_window = main_window_spawn_clone.lock().unwrap(); let main_window = main_window_spawn_clone.lock().unwrap();
@ -685,14 +681,12 @@ pub async fn register_shortcut(_token: APIToken, payload: Json<RegisterShortcutR
let mut registered_shortcuts = REGISTERED_SHORTCUTS.lock().unwrap(); let mut registered_shortcuts = REGISTERED_SHORTCUTS.lock().unwrap();
// Unregister the old shortcut if one exists for this name: // Unregister the old shortcut if one exists for this name:
if let Some(old_shortcut) = registered_shortcuts.get(&id) { if let Some(old_shortcut) = registered_shortcuts.get(&id) && !old_shortcut.is_empty() {
if !old_shortcut.is_empty() {
match shortcut_manager.unregister(old_shortcut.as_str()) { match shortcut_manager.unregister(old_shortcut.as_str()) {
Ok(_) => info!(Source = "Tauri"; "Unregistered old shortcut '{old_shortcut}' for '{}'.", id), Ok(_) => info!(Source = "Tauri"; "Unregistered old shortcut '{old_shortcut}' for '{}'.", id),
Err(error) => warn!(Source = "Tauri"; "Failed to unregister old shortcut '{old_shortcut}': {error}"), Err(error) => warn!(Source = "Tauri"; "Failed to unregister old shortcut '{old_shortcut}': {error}"),
} }
} }
}
// When the new shortcut is empty, we're done (just unregistering): // When the new shortcut is empty, we're done (just unregistering):
if new_shortcut.is_empty() { if new_shortcut.is_empty() {

View File

@ -87,11 +87,9 @@ fn normalize_locale_tag(locale: &str) -> Option<String> {
return None; return None;
} }
if let Some(region) = segments.next() { if let Some(region) = segments.next() && region.len() == 2 && region.chars().all(|c| c.is_ascii_alphabetic()) {
if region.len() == 2 && region.chars().all(|c| c.is_ascii_alphabetic()) {
return Some(format!("{}-{}", language, region.to_ascii_uppercase())); return Some(format!("{}-{}", language, region.to_ascii_uppercase()));
} }
}
Some(language) Some(language)
} }
@ -418,12 +416,11 @@ fn load_policy_values_from_directories(directories: &[PathBuf]) -> HashMap<Strin
} }
let secret_path = directory.join(ENTERPRISE_POLICY_SECRET_FILE_NAME); let secret_path = directory.join(ENTERPRISE_POLICY_SECRET_FILE_NAME);
if let Some(secret_values) = read_policy_yaml_mapping(&secret_path) { if let Some(secret_values) = read_policy_yaml_mapping(&secret_path)
if let Some(secret) = secret_values.get("config_encryption_secret") { && let Some(secret) = secret_values.get("config_encryption_secret") {
insert_first_non_empty_value(&mut values, "config_encryption_secret", secret); insert_first_non_empty_value(&mut values, "config_encryption_secret", secret);
} }
} }
}
values values
} }

View File

@ -119,8 +119,8 @@ impl PandocProcessBuilder {
let local_installation_root_directory = data_folder.join("pandoc"); let local_installation_root_directory = data_folder.join("pandoc");
let executable_name = Self::pandoc_executable_name(); let executable_name = Self::pandoc_executable_name();
if local_installation_root_directory.exists() { if local_installation_root_directory.exists()
if let Ok(pandoc_path) = Self::find_executable_in_dir(&local_installation_root_directory, &executable_name) { && let Ok(pandoc_path) = Self::find_executable_in_dir(&local_installation_root_directory, &executable_name) {
HAS_LOGGED_PANDOC_PATH.get_or_init(|| { HAS_LOGGED_PANDOC_PATH.get_or_init(|| {
info!(Source = "PandocProcessBuilder"; "Found local Pandoc installation at: '{}'.", pandoc_path.to_string_lossy() info!(Source = "PandocProcessBuilder"; "Found local Pandoc installation at: '{}'.", pandoc_path.to_string_lossy()
); );
@ -131,7 +131,6 @@ impl PandocProcessBuilder {
is_local_installation: true, is_local_installation: true,
}; };
} }
}
for candidate in Self::system_pandoc_executable_candidates(&executable_name) { for candidate in Self::system_pandoc_executable_candidates(&executable_name) {
if candidate.exists() && candidate.is_file() { if candidate.exists() && candidate.is_file() {
@ -168,13 +167,11 @@ impl PandocProcessBuilder {
if let Ok(entries) = fs::read_dir(dir) { if let Ok(entries) = fs::read_dir(dir) {
for entry in entries.flatten() { for entry in entries.flatten() {
let path = entry.path(); let path = entry.path();
if path.is_dir() { if path.is_dir() && let Ok(found_path) = Self::find_executable_in_dir(&path, executable_name) {
if let Ok(found_path) = Self::find_executable_in_dir(&path, executable_name) {
return Ok(found_path); return Ok(found_path);
} }
} }
} }
}
Err("Executable not found".into()) Err("Executable not found".into())
} }
@ -240,8 +237,7 @@ impl PandocProcessBuilder {
let runtime_os = std::env::consts::OS; let runtime_os = std::env::consts::OS;
let runtime_arch = std::env::consts::ARCH; let runtime_arch = std::env::consts::ARCH;
if let Ok(metadata) = META_DATA.lock() { if let Ok(metadata) = META_DATA.lock() && let Some(metadata) = metadata.as_ref() {
if let Some(metadata) = metadata.as_ref() {
let metadata_arch = &metadata.architecture; let metadata_arch = &metadata.architecture;
// Determine expected OS from metadata: // Determine expected OS from metadata:
@ -268,7 +264,6 @@ impl PandocProcessBuilder {
); );
} }
} }
}
}); });
// Use std::env::consts::OS for runtime detection instead of metadata // Use std::env::consts::OS for runtime detection instead of metadata

View File

@ -100,12 +100,10 @@ pub async fn qdrant_port(_token: APIToken) -> Json<ProvideQdrantInfo> {
/// Starts the Qdrant server in a separate process. /// Starts the Qdrant server in a separate process.
pub fn start_qdrant_server<R: tauri::Runtime>(app_handle: tauri::AppHandle<R>){ pub fn start_qdrant_server<R: tauri::Runtime>(app_handle: tauri::AppHandle<R>){
let path = qdrant_base_path(); let path = qdrant_base_path();
if !path.exists() { if !path.exists() && let Err(e) = fs::create_dir_all(&path){
if let Err(e) = fs::create_dir_all(&path){
error!(Source="Qdrant"; "The required directory to host the Qdrant database could not be created: {}", e); error!(Source="Qdrant"; "The required directory to host the Qdrant database could not be created: {}", e);
set_qdrant_unavailable(format!("The Qdrant data directory could not be created: {e}")); set_qdrant_unavailable(format!("The Qdrant data directory could not be created: {e}"));
return; return;
};
} }
let (cert_path, key_path) = match create_temp_tls_files(&path) { let (cert_path, key_path) = match create_temp_tls_files(&path) {

View File

@ -50,7 +50,7 @@ pub fn kill_stale_process(pid_file_path: PathBuf, sidecar_type: SidecarType) ->
let killed = process.kill_with(Signal::Kill).unwrap_or_else(|| process.kill()); let killed = process.kill_with(Signal::Kill).unwrap_or_else(|| process.kill());
if !killed { if !killed {
return Err(Error::new(ErrorKind::Other, "Failed to kill process")); return Err(Error::other("Failed to kill process"));
} }
info!(Source="Stale Process Cleanup";"{}: Killed process: \"{}\"", sidecar_type,pid_file_path.display()); info!(Source="Stale Process Cleanup";"{}: Killed process: \"{}\"", sidecar_type,pid_file_path.display());
} else { } else {