From 6229f08200c71b74cca9364f6f0edac883f9b568 Mon Sep 17 00:00:00 2001 From: David Adam Date: Mon, 19 Jun 2023 21:57:53 +0800 Subject: [PATCH] rust/print_help: simplify use of OsStrings See discussion in https://github.com/fish-shell/fish-shell/pull/9818#discussion_r1210829722 --- fish-rust/src/print_help.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/fish-rust/src/print_help.rs b/fish-rust/src/print_help.rs index bad600f24..3f9c96311 100644 --- a/fish-rust/src/print_help.rs +++ b/fish-rust/src/print_help.rs @@ -3,7 +3,6 @@ use libc::c_char; use std::ffi::{CStr, OsStr, OsString}; -use std::os::unix::ffi::OsStrExt; use std::process::Command; const HELP_ERR: &str = "Could not show help message"; @@ -15,7 +14,7 @@ mod ffi2 { } } -fn print_help(command: &OsStr) { +fn print_help(command: &str) { let mut cmdline = OsString::new(); cmdline.push("__fish_print_help "); cmdline.push(command); @@ -28,6 +27,6 @@ fn print_help(command: &OsStr) { unsafe fn unsafe_print_help(command_buf: *const c_char) { let command_cstr: &CStr = unsafe { CStr::from_ptr(command_buf) }; - let command = OsStr::from_bytes(command_cstr.to_bytes()); + let command = command_cstr.to_str().unwrap(); print_help(command); }