Debian Codegraph @

third_party/rust/tokio/src/fs/copy.rs

raw
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`].
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
21 pub async fn copy(from: impl AsRef<Path>, to: impl AsRef<Path>) -> Result<u64, std::io::Error> {
22 let from = from.as_ref().to_owned();
23 let to = to.as_ref().to_owned();
24 asyncify(|| std::fs::copy(from, to)).await
25 }