Invert &Options to Option<&T> (#10315)

Elide the reference for `Copy` type (`usize`)
Use the canonical deref where possible.
* `&Box` -> `&`
* `&String` -> `&str`
* `&PathBuf` -> `&Path`

Skips the ctrl-C handler for now.
This commit is contained in:
Stefan Holderbach
2023-09-13 01:00:58 +02:00
committed by GitHub
parent 3e14dc3eb8
commit a14e9e0a2e
24 changed files with 87 additions and 83 deletions

View File

@ -66,7 +66,7 @@ impl Command for PluginDeclaration {
// Decode information from plugin
// Create PipelineData
let source_file = Path::new(&self.filename);
let mut plugin_cmd = create_command(source_file, &self.shell);
let mut plugin_cmd = create_command(source_file, self.shell.as_deref());
// We need the current environment variables for `python` based plugins
// Or we'll likely have a problem when a plugin is implemented in a virtual Python environment.
let current_envs = nu_engine::env::env_to_strings(engine_state, stack).unwrap_or_default();
@ -175,7 +175,7 @@ impl Command for PluginDeclaration {
pipeline_data
}
fn is_plugin(&self) -> Option<(&PathBuf, &Option<PathBuf>)> {
Some((&self.filename, &self.shell))
fn is_plugin(&self) -> Option<(&Path, Option<&Path>)> {
Some((&self.filename, self.shell.as_deref()))
}
}

View File

@ -8,7 +8,7 @@ use crate::EncodingType;
use std::env;
use std::fmt::Write;
use std::io::{BufReader, ErrorKind, Read, Write as WriteTrait};
use std::path::{Path, PathBuf};
use std::path::Path;
use std::process::{Child, ChildStdout, Command as CommandSys, Stdio};
use nu_protocol::{CustomValue, PluginSignature, ShellError, Span, Value};
@ -48,7 +48,7 @@ pub trait PluginEncoder: Clone {
) -> Result<PluginResponse, ShellError>;
}
pub(crate) fn create_command(path: &Path, shell: &Option<PathBuf>) -> CommandSys {
pub(crate) fn create_command(path: &Path, shell: Option<&Path>) -> CommandSys {
let mut process = match (path.extension(), shell) {
(_, Some(shell)) => {
let mut process = std::process::Command::new(shell);
@ -124,7 +124,7 @@ pub(crate) fn call_plugin(
#[doc(hidden)] // Note: not for plugin authors / only used in nu-parser
pub fn get_signature(
path: &Path,
shell: &Option<PathBuf>,
shell: Option<&Path>,
current_envs: &HashMap<String, String>,
) -> Result<Vec<PluginSignature>, ShellError> {
let mut plugin_cmd = create_command(path, shell);

View File

@ -45,7 +45,7 @@ impl CustomValue for PluginCustomValue {
&self,
span: nu_protocol::Span,
) -> Result<nu_protocol::Value, nu_protocol::ShellError> {
let mut plugin_cmd = create_command(&self.filename, &self.shell);
let mut plugin_cmd = create_command(&self.filename, self.shell.as_deref());
let mut child = plugin_cmd.spawn().map_err(|err| {
ShellError::GenericError(