• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 use crate::fs::asyncify;
2 use 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`][std].
9 ///
10 /// [std]: fn@std::fs::copy
11 ///
12 /// # Examples
13 ///
14 /// ```no_run
15 /// use tokio::fs;
16 ///
17 /// # async fn dox() -> std::io::Result<()> {
18 /// fs::copy("foo.txt", "bar.txt").await?;
19 /// # Ok(())
20 /// # }
21 /// ```
22 
copy(from: impl AsRef<Path>, to: impl AsRef<Path>) -> Result<u64, std::io::Error>23 pub async fn copy(from: impl AsRef<Path>, to: impl AsRef<Path>) -> Result<u64, std::io::Error> {
24     let from = from.as_ref().to_owned();
25     let to = to.as_ref().to_owned();
26     asyncify(|| std::fs::copy(from, to)).await
27 }
28