diff --git a/src/fs/file.rs b/src/fs/file.rs index 5b7c7b4..346b77a 100644 --- a/src/fs/file.rs +++ b/src/fs/file.rs @@ -41,4 +41,25 @@ impl<'base, 'path> PathReal<'base, 'path, FileMarker> { self.check_error()?; std::fs::write(self.as_pathbuf(), contents).map_err(Error::Io) } + + /// Copies the contents of a file to another file. + /// + /// Wrapper for [std::fs::copy] + /// + /// ``` + /// # fn try_main() -> kxio::fs::Result<()> { + /// let fs = kxio::fs::temp()?; + /// let src_path = fs.base().join("foo"); + /// let dest_path = fs.base().join("bar"); + /// let src = fs.file(&src_path); + /// # fs.file(&dest_path).write("new file contents")?; + /// let dest = fs.file(&dest_path); + /// src.copy(&dest)?; + /// # Ok(()) + /// # } + /// ``` + pub fn copy(&self, dest: &PathReal<'base, 'path, FileMarker>) -> Result { + self.check_error()?; + std::fs::copy(self.as_pathbuf(), dest.as_pathbuf()).map_err(Error::Io) + } }