refactor: replace Vec<T> with &[T] in function parameters (codeberg #7)

Reviewed-on: https://codeberg.org/iff/pay-respects/pulls/7
Co-authored-by: Integral <integral@member.fsf.org>
Co-committed-by: Integral <integral@member.fsf.org>
This commit is contained in:
Integral 2024-12-14 16:53:03 +00:00 committed by iff
parent 7c74d13705
commit 7c7cc4d285
5 changed files with 7 additions and 11 deletions

View file

@ -232,7 +232,7 @@ pub fn elevate(data: &mut Data, command: &mut String) {
pub fn add_candidates_no_dup( pub fn add_candidates_no_dup(
command: &str, command: &str,
candidates: &mut Vec<String>, candidates: &mut Vec<String>,
new_candidates: &Vec<String>, new_candidates: &[String],
) { ) {
for candidate in new_candidates { for candidate in new_candidates {
let candidate = candidate.trim(); let candidate = candidate.trim();

View file

@ -161,7 +161,7 @@ fn get_rule(executable: &str) -> Option<String> {
return Some(user_rule_file); return Some(user_rule_file);
} }
let check_dirs = |dirs: Vec<&str>| -> Option<String> { let check_dirs = |dirs: &[&str]| -> Option<String> {
for dir in dirs { for dir in dirs {
let rule_dir = format!("{}/pay-respects/rules", dir); let rule_dir = format!("{}/pay-respects/rules", dir);
let rule_file = format!("{}/{}.toml", rule_dir, executable); let rule_file = format!("{}/{}.toml", rule_dir, executable);
@ -175,7 +175,7 @@ fn get_rule(executable: &str) -> Option<String> {
let xdg_config_dirs = std::env::var("XDG_CONFIG_DIRS").unwrap_or("/etc/xdg".to_owned()); let xdg_config_dirs = std::env::var("XDG_CONFIG_DIRS").unwrap_or("/etc/xdg".to_owned());
let xdg_config_dirs = xdg_config_dirs.split(':').collect::<Vec<&str>>(); let xdg_config_dirs = xdg_config_dirs.split(':').collect::<Vec<&str>>();
if let Some(file) = check_dirs(xdg_config_dirs) { if let Some(file) = check_dirs(&xdg_config_dirs) {
return Some(file); return Some(file);
} }
@ -183,7 +183,7 @@ fn get_rule(executable: &str) -> Option<String> {
std::env::var("XDG_DATA_DIRS").unwrap_or("/usr/local/share:/usr/share".to_owned()); std::env::var("XDG_DATA_DIRS").unwrap_or("/usr/local/share:/usr/share".to_owned());
let xdg_data_dirs = xdg_data_dirs.split(':').collect::<Vec<&str>>(); let xdg_data_dirs = xdg_data_dirs.split(':').collect::<Vec<&str>>();
if let Some(file) = check_dirs(xdg_data_dirs) { if let Some(file) = check_dirs(&xdg_data_dirs) {
return Some(file); return Some(file);
} }

View file

@ -57,7 +57,7 @@ fn get_rules(directory: String) -> Vec<Rule> {
rules rules
} }
fn gen_match_rules(rules: Vec<Rule>) -> TokenStream { fn gen_match_rules(rules: &[Rule]) -> TokenStream {
let command = rules let command = rules
.iter() .iter()
.map(|x| x.command.to_owned()) .map(|x| x.command.to_owned())

View file

@ -238,11 +238,7 @@ pub fn shell(suggest: &mut String, cmd_list: &mut Vec<String>) {
} }
} }
pub fn shell_tag( pub fn shell_tag(suggest: &mut String, replace_list: &mut Vec<TokenStream2>, cmd_list: &[String]) {
suggest: &mut String,
replace_list: &mut Vec<TokenStream2>,
cmd_list: Vec<String>,
) {
let mut replace_tag = 0; let mut replace_tag = 0;
let tag_name = "shell"; let tag_name = "shell";

View file

@ -69,7 +69,7 @@ pub fn split_command(command: &str) -> Vec<String> {
split_command split_command
} }
pub fn suggest_typo(typos: &[String], candidates: Vec<String>, executables: &[String]) -> String { pub fn suggest_typo(typos: &[String], candidates: &[String], executables: &[String]) -> String {
let mut suggestions = Vec::new(); let mut suggestions = Vec::new();
for typo in typos { for typo in typos {
let typo = typo.as_str(); let typo = typo.as_str();