Eliding some lifetimes

This commit is contained in:
João M. Bezerra 2021-05-28 03:14:03 -03:00
parent f51a5c8727
commit d1734b54cb
2 changed files with 5 additions and 17 deletions

View File

@ -52,10 +52,7 @@ pub struct ParsedArgs {
/// check_for_typo checks if the first argument is /// check_for_typo checks if the first argument is
/// a typo for the compress subcommand. /// a typo for the compress subcommand.
/// Returns true if the arg is probably a typo or false otherwise. /// Returns true if the arg is probably a typo or false otherwise.
fn is_typo<'a, P>(path: P) -> bool fn is_typo(path: impl AsRef<Path>) -> bool {
where
P: AsRef<Path> + 'a,
{
if path.as_ref().exists() { if path.as_ref().exists() {
// If the file exists then we won't check for a typo // If the file exists then we won't check for a typo
return false; return false;
@ -66,10 +63,7 @@ where
normalized_damerau_levenshtein("compress", &path) > 0.625 normalized_damerau_levenshtein("compress", &path) > 0.625
} }
fn canonicalize<'a, P>(path: P) -> crate::Result<PathBuf> fn canonicalize(path: impl AsRef<Path>) -> crate::Result<PathBuf> {
where
P: AsRef<Path> + 'a,
{
match std::fs::canonicalize(&path.as_ref()) { match std::fs::canonicalize(&path.as_ref()) {
Ok(abs_path) => Ok(abs_path), Ok(abs_path) => Ok(abs_path),
Err(io_err) => { Err(io_err) => {
@ -82,11 +76,8 @@ where
} }
} }
fn canonicalize_files<'a, P>(files: &[P]) -> crate::Result<Vec<PathBuf>> fn canonicalize_files(files: &[impl AsRef<Path>]) -> crate::Result<Vec<PathBuf>> {
where files.iter().map(canonicalize).collect()
P: AsRef<Path> + 'a,
{
files.into_iter().map(canonicalize).collect()
} }
pub fn parse_args_from(mut args: Vec<OsString>) -> crate::Result<ParsedArgs> { pub fn parse_args_from(mut args: Vec<OsString>) -> crate::Result<ParsedArgs> {

View File

@ -23,10 +23,7 @@ macro_rules! debug {
}; };
} }
pub fn ensure_exists<'a, P>(path: P) -> crate::Result<()> pub fn ensure_exists(path: impl AsRef<Path>) -> crate::Result<()> {
where
P: AsRef<Path> + 'a,
{
let exists = path.as_ref().exists(); let exists = path.as_ref().exists();
if !exists { if !exists {
return Err(crate::Error::FileNotFound(PathBuf::from(path.as_ref()))); return Err(crate::Error::FileNotFound(PathBuf::from(path.as_ref())));