pub async fn copy<P: AsRef<Path>, Q: AsRef<Path>>(src: P, dst: Q) -> Result<u64>
Expand description

Copies a file to a new location.

On success, the total number of bytes copied is returned and equals the length of the dst file after this operation.

The old contents of dst will be overwritten. If src and dst both point to the same file, then the file will likely get truncated as a result of this operation.

If you’re working with open Files and want to copy contents through those types, use futures_lite::io::copy() instead.

Errors

An error will be returned in the following situations:

  • src does not point to an existing file.
  • The current process lacks permissions to read src or write dst.
  • Some other I/O error occurred.

Examples

let num_bytes = async_fs::copy("a.txt", "b.txt").await?;