From 25d207a8cef0a46194ebde8ed72d8c532b54cb86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20H=C3=B8rl=C3=BCck=20Berg?= <36937807+henrikhorluck@users.noreply.github.com> Date: Sat, 19 Aug 2023 19:58:49 +0200 Subject: [PATCH] Make get_current_exe use impl AsRef - It does not need to require the default to be valid UTF8 --- fish-rust/src/common.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/fish-rust/src/common.rs b/fish-rust/src/common.rs index 8a7364f3c..39fe7c010 100644 --- a/fish-rust/src/common.rs +++ b/fish-rust/src/common.rs @@ -27,8 +27,7 @@ use std::ffi::{CStr, CString, OsStr, OsString}; use std::mem; use std::ops::{Deref, DerefMut}; use std::os::unix::prelude::*; -use std::path::PathBuf; -use std::str::FromStr; +use std::path::{Path, PathBuf}; use std::sync::atomic::{AtomicI32, AtomicU32, Ordering}; use std::sync::{Arc, Mutex, TryLockError}; use std::time; @@ -1772,7 +1771,7 @@ pub fn valid_var_name(s: &wstr) -> bool { } /// Get the absolute path to the fish executable itself -pub fn get_executable_path(argv0: &str) -> PathBuf { +pub fn get_executable_path(argv0: impl AsRef) -> PathBuf { if let Ok(path) = std::env::current_exe() { if path.exists() { return path; @@ -1794,7 +1793,7 @@ pub fn get_executable_path(argv0: &str) -> PathBuf { } return path; } - PathBuf::from_str(argv0).unwrap() + argv0.as_ref().to_owned() } /// A RAII cleanup object. Unlike in C++ where there is no borrow checker, we can't just provide a