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

@ -469,9 +469,9 @@ pub fn read_std(std: &[u8]) -> String {
out.replace('\n', "")
}
use std::{path::PathBuf, process::Command};
use std::{path::Path, process::Command};
pub fn run_command(executable_path: &PathBuf, target_cwd: &str) -> Command {
pub fn run_command(executable_path: &Path, target_cwd: &str) -> Command {
let mut command = Command::new(executable_path);
command

View File

@ -30,7 +30,7 @@ pub fn says() -> Play {
trait CheckerMatchers {
fn output(&self, actual: &Outcome) -> MatchResult;
fn std(&self, actual: &[u8], expected: Option<&String>, description: &str) -> MatchResult;
fn std(&self, actual: &[u8], expected: Option<&str>, description: &str) -> MatchResult;
fn stdout(&self, actual: &Outcome) -> MatchResult;
}
@ -40,10 +40,10 @@ impl CheckerMatchers for Play {
}
fn stdout(&self, actual: &Outcome) -> MatchResult {
self.std(&actual.out, self.stdout_expectation.as_ref(), "stdout")
self.std(&actual.out, self.stdout_expectation.as_deref(), "stdout")
}
fn std(&self, actual: &[u8], expected: Option<&String>, description: &str) -> MatchResult {
fn std(&self, actual: &[u8], expected: Option<&str>, description: &str) -> MatchResult {
let out = match expected {
Some(out) => out,
None => return Ok(()),
@ -51,7 +51,7 @@ impl CheckerMatchers for Play {
let actual =
str::from_utf8(actual).map_err(|_| format!("{description} was not utf8 encoded"))?;
if actual != *out {
if actual != out {
return Err(format!(
"not equal:\n actual: {actual}\n expected: {out}\n\n"
));

View File

@ -46,12 +46,12 @@ impl Dirs {
self.fixtures.join("playground/config")
}
pub fn root(&self) -> &PathBuf {
&self.root
pub fn root(&self) -> &Path {
self.root.as_path()
}
pub fn test(&self) -> &PathBuf {
&self.test
pub fn test(&self) -> &Path {
self.test.as_path()
}
}