diff --git a/src/index/io.rs b/src/index/io.rs index 0c94887..8c6ab07 100644 --- a/src/index/io.rs +++ b/src/index/io.rs @@ -43,20 +43,16 @@ impl Index { self.version = max(self.version, index.version); } self.version = self.version.next(); - self.write_index_to_file(self.index_file_path())?; + self.write_index_to_file(&self.index_file_path())?; lock.release()?; log::debug!("[{}] saved index version {} with lock id {}", getpid(), self.version, lock_id,); Ok(()) } - fn write_index_to_file(&mut self, path: T) -> Result<()> - where - T: AsRef, - { + fn write_index_to_file(&mut self, path: &Path) -> Result<()> { fs::create_dir_all( - path.as_ref() - .parent() - .ok_or_else(|| anyhow!("cannot compute parent path for {}", path.as_ref().to_string_lossy()))?, + path.parent() + .ok_or_else(|| anyhow!("cannot compute parent path for {}", path.to_string_lossy()))?, ) .context("create index directory")?; diff --git a/src/index/lock.rs b/src/index/lock.rs index 8967747..ce6d727 100644 --- a/src/index/lock.rs +++ b/src/index/lock.rs @@ -14,7 +14,8 @@ pub struct Lock { } impl Lock { - pub fn lock(index_directory: &Path) -> Result { + pub fn lock>(index_directory: T) -> Result { + let index_directory = index_directory.as_ref(); let mut buffer = [0u8; 16]; OsRng.fill_bytes(&mut buffer); let id = Uuid::from_bytes(buffer); diff --git a/src/index/mod.rs b/src/index/mod.rs index e63110d..a8eeb10 100644 --- a/src/index/mod.rs +++ b/src/index/mod.rs @@ -35,7 +35,9 @@ impl Index { } } - pub fn remember(&mut self, original_source_path: &Path, relative_path: &Path, id: ItemId) { + pub fn remember, R: AsRef>(&mut self, original_source_path: S, relative_path: R, id: ItemId) { + let original_source_path = original_source_path.as_ref(); + let relative_path = relative_path.as_ref(); let item = if let Some(old) = self .newest_items_by_source_path .get(&original_source_path.to_string_lossy().to_string()) @@ -71,7 +73,8 @@ impl Index { ) } - pub fn newest_item_by_source_path(&self, path: &Path) -> Result> { + pub fn newest_item_by_source_path>(&self, path: T) -> Result> { + let path = path.as_ref(); if !path.is_absolute() { return Err(anyhow!("repository path not absolute")); } diff --git a/src/repository/mod.rs b/src/repository/mod.rs index bb3f64f..cd99d8f 100644 --- a/src/repository/mod.rs +++ b/src/repository/mod.rs @@ -82,19 +82,13 @@ impl fmt::Display for ItemId { } impl<'a> Repository { - pub fn init(path: T) -> Result<()> - where - T: AsRef, - { + pub fn init>(path: T) -> Result<()> { let mut index = Index::new(path.as_ref()); index.save()?; Ok(()) } - pub fn open(path: T) -> Result - where - T: AsRef, - { + pub fn open>(path: T) -> Result { let path = path.as_ref(); if !path.is_absolute() { return Err(anyhow!("path to repository not absolute"));