Change a few methods to take AsRef<Path>

This commit is contained in:
Charlie Marsh
2022-12-16 21:28:19 -05:00
parent ecf0dd05d6
commit f36e6035c8
2 changed files with 3 additions and 3 deletions

View File

@@ -64,7 +64,7 @@ pub fn relativize_path(path: &Path) -> Cow<str> {
}
/// Read a file's contents from disk.
pub(crate) fn read_file(path: &Path) -> Result<String> {
pub(crate) fn read_file<P: AsRef<Path>>(path: P) -> Result<String> {
let file = File::open(path)?;
let mut buf_reader = BufReader::new(file);
let mut contents = String::new();

View File

@@ -28,13 +28,13 @@ impl Pyproject {
}
}
fn parse_pyproject_toml(path: &Path) -> Result<Pyproject> {
fn parse_pyproject_toml<P: AsRef<Path>>(path: P) -> Result<Pyproject> {
let contents = fs::read_file(path)?;
toml::from_str(&contents).map_err(std::convert::Into::into)
}
/// Return `true` if a `pyproject.toml` contains a `[tool.ruff]` section.
pub fn has_ruff_section(path: &Path) -> Result<bool> {
pub fn has_ruff_section<P: AsRef<Path>>(path: P) -> Result<bool> {
let pyproject = parse_pyproject_toml(path)?;
Ok(pyproject.tool.and_then(|tool| tool.ruff).is_some())
}