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

@ -87,7 +87,7 @@ impl Command for Save {
match input {
PipelineData::ExternalStream { stdout: None, .. } => {
// Open files to possibly truncate them
let _ = get_files(&path, &stderr_path, append, force)?;
let _ = get_files(&path, stderr_path.as_ref(), append, force)?;
Ok(PipelineData::empty())
}
PipelineData::ExternalStream {
@ -95,7 +95,7 @@ impl Command for Save {
stderr,
..
} => {
let (file, stderr_file) = get_files(&path, &stderr_path, append, force)?;
let (file, stderr_file) = get_files(&path, stderr_path.as_ref(), append, force)?;
// delegate a thread to redirect stderr to result.
let handler = stderr.map(|stderr_stream| match stderr_file {
@ -127,7 +127,7 @@ impl Command for Save {
PipelineData::ListStream(ls, _)
if raw || prepare_path(&path, append, force)?.0.extension().is_none() =>
{
let (mut file, _) = get_files(&path, &stderr_path, append, force)?;
let (mut file, _) = get_files(&path, stderr_path.as_ref(), append, force)?;
for val in ls {
file.write_all(&value_to_bytes(val)?)
.map_err(|err| ShellError::IOError(err.to_string()))?;
@ -143,7 +143,7 @@ impl Command for Save {
input_to_bytes(input, Path::new(&path.item), raw, engine_state, stack, span)?;
// Only open file after successful conversion
let (mut file, _) = get_files(&path, &stderr_path, append, force)?;
let (mut file, _) = get_files(&path, stderr_path.as_ref(), append, force)?;
file.write_all(&bytes)
.map_err(|err| ShellError::IOError(err.to_string()))?;
@ -317,7 +317,7 @@ fn open_file(path: &Path, span: Span, append: bool) -> Result<File, ShellError>
/// Get output file and optional stderr file
fn get_files(
path: &Spanned<PathBuf>,
stderr_path: &Option<Spanned<PathBuf>>,
stderr_path: Option<&Spanned<PathBuf>>,
append: bool,
force: bool,
) -> Result<(File, Option<File>), ShellError> {