Function rename

Source
pub fn rename<P: AsRef<Path>, Q: AsRef<Path>>(
    from: P,
    to: Q,
) -> Result<(), FileError>
Expand description

Renames a file.

This function is identical to mv.

§Arguments

  • from - The current path of the file.
  • to - The new path for the file.

§Returns

Returns a Result containing () if successful, or a FileError.

§Examples

use dev_utils::file::{create, rename, read};
use std::path::Path;

let original = create("original.txt", "Hello").unwrap();
rename(&original, "renamed.txt").unwrap();
assert!(!Path::new("original.txt").exists());
assert_eq!(read("renamed.txt").unwrap(), "Hello");