Skip to content

Commit 9653a00

Browse files
committed
fix(*): more direct Intos
1 parent 31f2844 commit 9653a00

4 files changed

Lines changed: 21 additions & 23 deletions

File tree

brush-builtins/src/printf.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use clap::Parser;
2-
use std::{io::Write, ops::ControlFlow};
2+
use std::{ffi::OsString, io::Write, ops::ControlFlow};
33
use uucore::format;
44

55
use brush_core::{Error, ErrorKind, ExecutionResult, builtins, escape, expansion};
@@ -83,12 +83,12 @@ fn format_special_case_for_percent_q(
8383

8484
fn format_via_uucore(
8585
format_string: &str,
86-
args: impl Iterator<Item = impl AsRef<str>>,
86+
args: impl Iterator<Item = impl Into<OsString>>,
8787
mut writer: impl Write,
8888
) -> Result<(), brush_core::Error> {
8989
// Convert string arguments to FormatArgument::Unparsed
9090
let format_args: Vec<_> = args
91-
.map(|s| format::FormatArgument::Unparsed(s.as_ref().to_string().into()))
91+
.map(|s| format::FormatArgument::Unparsed(s.into()))
9292
.collect();
9393

9494
// Parse format string once.
@@ -149,7 +149,7 @@ mod tests {
149149

150150
fn sprintf_via_uucore(
151151
format_string: &str,
152-
args: impl Iterator<Item = impl AsRef<str>>,
152+
args: impl Iterator<Item = impl Into<OsString>>,
153153
) -> Result<String> {
154154
let mut result = vec![];
155155
format_via_uucore(format_string, args, &mut result)?;

brush-core/src/pathcache.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ impl PathCache {
3232
///
3333
/// * `name` - The name to set.
3434
/// * `path` - The path to associate with the name.
35-
pub fn set<S: AsRef<str>>(&mut self, name: S, path: PathBuf) {
36-
self.cache.insert(name.as_ref().to_string(), path);
35+
pub fn set<T: Into<String>>(&mut self, name: T, path: PathBuf) {
36+
self.cache.insert(name.into(), path);
3737
}
3838

3939
/// Projects the cache into a shell value.

brush-core/src/pathsearch.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@ use std::{collections::VecDeque, path::PathBuf};
55
use crate::sys::fs::PathExt;
66

77
/// Encapsulates the result of a path search.
8-
pub struct ExecutablePathSearch<PI, N>
9-
where
10-
PI: AsRef<str>,
11-
N: AsRef<str>,
12-
{
8+
pub struct ExecutablePathSearch<PI, N> {
139
paths: VecDeque<PI>,
1410
filename: N,
1511
}
@@ -33,10 +29,7 @@ where
3329
}
3430
}
3531

36-
pub(crate) struct ExecutablePathPrefixSearch<PI>
37-
where
38-
PI: AsRef<str>,
39-
{
32+
pub(crate) struct ExecutablePathPrefixSearch<PI> {
4033
paths: VecDeque<PI>,
4134
queued_items: VecDeque<PathBuf>,
4235
filename_prefix: String,

brush-core/src/shell.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,7 @@ impl<SE: extensions::ShellExtensions> Shell<SE> {
964964
/// * `path` - The path to the file to source.
965965
/// * `args` - The arguments to pass to the script as positional parameters.
966966
/// * `params` - Execution parameters.
967-
pub async fn source_script<S: AsRef<str>, P: AsRef<Path>, I: Iterator<Item = S>>(
967+
pub async fn source_script<S: Into<String>, P: AsRef<Path>, I: Iterator<Item = S>>(
968968
&mut self,
969969
path: P,
970970
args: I,
@@ -987,7 +987,11 @@ impl<SE: extensions::ShellExtensions> Shell<SE> {
987987
/// * `args` - The arguments to pass to the script as positional parameters.
988988
/// * `params` - Execution parameters.
989989
/// * `call_type` - The type of script call being made.
990-
async fn parse_and_execute_script_file<S: AsRef<str>, P: AsRef<Path>, I: Iterator<Item = S>>(
990+
async fn parse_and_execute_script_file<
991+
S: Into<String>,
992+
P: AsRef<Path>,
993+
I: Iterator<Item = S>,
994+
>(
991995
&mut self,
992996
path: P,
993997
args: I,
@@ -1040,7 +1044,7 @@ impl<SE: extensions::ShellExtensions> Shell<SE> {
10401044
/// * `args` - The arguments to pass to the script as positional parameters.
10411045
/// * `params` - Execution parameters.
10421046
/// * `call_type` - The type of script call being made.
1043-
async fn source_file<F: Read, S: AsRef<str>, I: Iterator<Item = S>>(
1047+
async fn source_file<F: Read, S: Into<String>, I: Iterator<Item = S>>(
10441048
&mut self,
10451049
file: F,
10461050
source_info: &crate::SourceInfo,
@@ -1054,7 +1058,7 @@ impl<SE: extensions::ShellExtensions> Shell<SE> {
10541058
tracing::debug!(target: trace_categories::PARSE, "Parsing sourced file: {}", source_info.source);
10551059
let parse_result = parser.parse_program();
10561060

1057-
let script_positional_args = args.map(|s| s.as_ref().to_owned());
1061+
let script_positional_args = args.map(Into::into);
10581062

10591063
self.call_stack
10601064
.push_script(call_type, source_info, script_positional_args);
@@ -1195,7 +1199,7 @@ impl<SE: extensions::ShellExtensions> Shell<SE> {
11951199
///
11961200
/// * `script_path` - The path to the script file to execute.
11971201
/// * `args` - The arguments to pass to the script as positional parameters.
1198-
pub async fn run_script<S: AsRef<str>, P: AsRef<Path>, I: Iterator<Item = S>>(
1202+
pub async fn run_script<S: Into<String>, P: AsRef<Path>, I: Iterator<Item = S>>(
11991203
&mut self,
12001204
script_path: P,
12011205
args: I,
@@ -1690,15 +1694,16 @@ impl<SE: extensions::ShellExtensions> Shell<SE> {
16901694
/// # Arguments
16911695
///
16921696
/// * `candidate_name` - The name of the file to look for.
1693-
pub fn find_first_executable_in_path_using_cache<S: AsRef<str>>(
1697+
pub fn find_first_executable_in_path_using_cache<T: Into<String>>(
16941698
&mut self,
1695-
candidate_name: S,
1699+
candidate_name: T,
16961700
) -> Option<PathBuf> {
1701+
let candidate_name = candidate_name.into();
16971702
if let Some(cached_path) = self.program_location_cache.get(&candidate_name) {
16981703
Some(cached_path)
16991704
} else if let Some(found_path) = self.find_first_executable_in_path(&candidate_name) {
17001705
self.program_location_cache
1701-
.set(&candidate_name, found_path.clone());
1706+
.set(candidate_name, found_path.clone());
17021707
Some(found_path)
17031708
} else {
17041709
None

0 commit comments

Comments
 (0)