feat(fs): add copy
This commit is contained in:
parent
a879c6fa15
commit
55a73cbbf1
1 changed files with 21 additions and 0 deletions
|
@ -41,4 +41,25 @@ impl<'base, 'path> PathReal<'base, 'path, FileMarker> {
|
||||||
self.check_error()?;
|
self.check_error()?;
|
||||||
std::fs::write(self.as_pathbuf(), contents).map_err(Error::Io)
|
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<u64> {
|
||||||
|
self.check_error()?;
|
||||||
|
std::fs::copy(self.as_pathbuf(), dest.as_pathbuf()).map_err(Error::Io)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue