summaryrefslogtreecommitdiffstats
path: root/tokio-fs/src/rename.rs
blob: 16c966631b899f3d5fdf8fc20fb9929d981bedb2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use crate::asyncify;

use std::io;
use std::path::Path;

/// Rename a file or directory to a new name, replacing the original file if
/// `to` already exists.
///
/// This will not work if the new name is on a different mount point.
///
/// This is an async version of [`std::fs::rename`](std::fs::rename)
pub async fn rename<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> io::Result<()> {
    let from = from.as_ref().to_owned();
    let to = to.as_ref().to_owned();

    asyncify(move || std::fs::rename(from, to)).await
}