Deref &String arguments to &str where appropriate (#10321)

# Description
This generally makes for nicer APIs, as you are not forced to use an
existing allocation covering the full `String`.

Some exceptions remain where the underlying type requirements favor it.

# User-Facing Changes
None
This commit is contained in:
Stefan Holderbach
2023-09-12 08:06:56 +02:00
committed by GitHub
parent e90b099622
commit 6e9b6f22c9
11 changed files with 70 additions and 71 deletions

View File

@ -376,8 +376,8 @@ impl Stack {
engine_state.env_vars.contains_key(name)
}
pub fn is_overlay_active(&self, name: &String) -> bool {
self.active_overlays.contains(name)
pub fn is_overlay_active(&self, name: &str) -> bool {
self.active_overlays.iter().any(|n| n == name)
}
pub fn add_overlay(&mut self, name: String) {
@ -385,7 +385,7 @@ impl Stack {
self.active_overlays.push(name);
}
pub fn remove_overlay(&mut self, name: &String) {
pub fn remove_overlay(&mut self, name: &str) {
self.active_overlays.retain(|o| o != name);
}
}

View File

@ -7,19 +7,19 @@ use crate::{
record, HistoryFileFormat, PipelineData, Range, Record, ShellError, Span, Value,
};
use nu_system::os_info::{get_kernel_version, get_os_arch, get_os_family, get_os_name};
use std::path::PathBuf;
use std::path::{Path, PathBuf};
pub fn create_nu_constant(engine_state: &EngineState, span: Span) -> Result<Value, ShellError> {
fn canonicalize_path(engine_state: &EngineState, path: &PathBuf) -> PathBuf {
fn canonicalize_path(engine_state: &EngineState, path: &Path) -> PathBuf {
let cwd = engine_state.current_work_dir();
if path.exists() {
match nu_path::canonicalize_with(path, cwd) {
Ok(canon_path) => canon_path,
Err(_) => path.clone(),
Err(_) => path.to_owned(),
}
} else {
path.clone()
path.to_owned()
}
}