diff --git a/src/db/stream.rs b/src/db/stream.rs index cdd280d..04b5c83 100644 --- a/src/db/stream.rs +++ b/src/db/stream.rs @@ -8,13 +8,10 @@ use crate::util::{self, MONTH}; pub struct Stream<'a> { db: &'a mut Database, idxs: Rev>, - keywords: Vec, - check_exists: bool, expire_below: Epoch, resolve_symlinks: bool, - exclude_path: Option, } @@ -38,7 +35,7 @@ impl<'a> Stream<'a> { } } - pub fn with_exclude>(mut self, path: S) -> Self { + pub fn with_exclude(mut self, path: impl Into) -> Self { self.exclude_path = Some(path.into()); self } @@ -49,7 +46,7 @@ impl<'a> Stream<'a> { self } - pub fn with_keywords>(mut self, keywords: &[S]) -> Self { + pub fn with_keywords(mut self, keywords: &[impl AsRef]) -> Self { self.keywords = keywords.iter().map(util::to_lowercase).collect(); self } @@ -80,15 +77,15 @@ impl<'a> Stream<'a> { None } - fn matches_exists>(&self, path: S) -> bool { + fn matches_exists(&self, path: &str) -> bool { if !self.check_exists { return true; } let resolver = if self.resolve_symlinks { fs::symlink_metadata } else { fs::metadata }; - resolver(path.as_ref()).map(|m| m.is_dir()).unwrap_or_default() + resolver(path).map(|m| m.is_dir()).unwrap_or_default() } - fn matches_keywords>(&self, path: S) -> bool { + fn matches_keywords(&self, path: &str) -> bool { let (keywords_last, keywords) = match self.keywords.split_last() { Some(split) => split, None => return true, diff --git a/src/util.rs b/src/util.rs index 7bf1bff..aa9c24a 100644 --- a/src/util.rs +++ b/src/util.rs @@ -149,7 +149,7 @@ impl FzfChild { } /// Similar to [`fs::write`], but atomic (best effort on Windows). -pub fn write, C: AsRef<[u8]>>(path: P, contents: C) -> Result<()> { +pub fn write(path: impl AsRef, contents: impl AsRef<[u8]>) -> Result<()> { let path = path.as_ref(); let contents = contents.as_ref(); let dir = path.parent().unwrap(); @@ -186,7 +186,7 @@ pub fn write, C: AsRef<[u8]>>(path: P, contents: C) -> Result<()> } /// Atomically create a tmpfile in the given directory. -fn tmpfile>(dir: P) -> Result<(File, PathBuf)> { +fn tmpfile(dir: impl AsRef) -> Result<(File, PathBuf)> { const MAX_ATTEMPTS: usize = 5; const TMP_NAME_LEN: usize = 16; let dir = dir.as_ref(); @@ -215,7 +215,7 @@ fn tmpfile>(dir: P) -> Result<(File, PathBuf)> { } /// Similar to [`fs::rename`], but with retries on Windows. -fn rename, Q: AsRef>(from: P, to: Q) -> Result<()> { +fn rename(from: impl AsRef, to: impl AsRef) -> Result<()> { let from = from.as_ref(); let to = to.as_ref(); @@ -232,8 +232,8 @@ fn rename, Q: AsRef>(from: P, to: Q) -> Result<()> { } } -pub fn canonicalize>(path: &P) -> Result { - dunce::canonicalize(path).with_context(|| format!("could not resolve path: {}", path.as_ref().display())) +pub fn canonicalize(path: impl AsRef) -> Result { + dunce::canonicalize(&path).with_context(|| format!("could not resolve path: {}", path.as_ref().display())) } pub fn current_dir() -> Result { @@ -247,14 +247,14 @@ pub fn current_time() -> Result { Ok(current_time) } -pub fn path_to_str>(path: &P) -> Result<&str> { +pub fn path_to_str(path: &impl AsRef) -> Result<&str> { let path = path.as_ref(); path.to_str().with_context(|| format!("invalid unicode in path: {}", path.display())) } /// Returns the absolute version of a path. Like [`std::path::Path::canonicalize`], but doesn't /// resolve symlinks. -pub fn resolve_path>(path: &P) -> Result { +pub fn resolve_path(path: impl AsRef) -> Result { let path = path.as_ref(); let base_path; @@ -265,7 +265,7 @@ pub fn resolve_path>(path: &P) -> Result { if cfg!(windows) { use std::path::Prefix; - fn get_drive_letter>(path: P) -> Option { + fn get_drive_letter(path: impl AsRef) -> Option { let path = path.as_ref(); let mut components = path.components(); @@ -359,7 +359,7 @@ pub fn resolve_path>(path: &P) -> Result { } /// Convert a string to lowercase, with a fast path for ASCII strings. -pub fn to_lowercase>(s: S) -> String { +pub fn to_lowercase(s: impl AsRef) -> String { let s = s.as_ref(); if s.is_ascii() { s.to_ascii_lowercase()