untrusted:: fs:: rename
pub fn rename<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> Result<()>
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 function currently corresponds to the
rename function on Unix
MoveFileEx function with the
MOVEFILE_REPLACE_EXISTING flag on Windows.
Because of this, the behavior when both
to exist differs. On
from is a directory,
to must also be an (empty) directory. If
from is not a directory,
to must also be not a directory. In contrast,
from can be anything, but
to must not be a directory.
Note that, this may change in the future.
This function will return an error in the following situations, but is not limited to just these cases:
fromdoes not exist.
- The user lacks permissions to view contents.
toare on separate filesystems.