1use crate::fs::asyncify;
2use std::path::Path;
3
4/// Copies the contents of one file to another. This function will also copy the permission bits
5/// of the original file to the destination file.
6/// This function will overwrite the contents of to.
7///
8/// This is the async equivalent of [`std::fs::copy`].
9///
10/// # Examples
11///
12/// ```no_run
13/// use tokio::fs;
14///
15/// # async fn dox() -> std::io::Result<()> {
16/// fs::copy("foo.txt", "bar.txt").await?;
17/// # Ok(())
18/// # }
19/// ```
20
21pub async fn copy(from: impl AsRef<Path>, to: impl AsRef<Path>) -> Result<u64, std::io::Error> {
22 let from: PathBuf = from.as_ref().to_owned();
23 let to: PathBuf = to.as_ref().to_owned();
24 asyncify(|| std::fs::copy(from, to)).await
25}
26