rename

Function rename 

Source
pub fn rename<From: AsRef<str>, To: AsRef<str>>(
    from: &From,
    to: &To,
) -> Result<()>
Expand description

Copies the contents of a file, writes it to a destination and then deletes the source. This function will entirely replace the contents of the destination if it already exists.

§Parameters

  • from: borrowed AsRef<str> such as String or &str
  • to: borrowed AsRef<str> such as String or &str

§Returns

Result<()>

§Examples

fn main() -> std::io::Result<()> {
    Ok({
        let source: &str = "file.1";
        let source: String = String::from(source);

        let destination: &str = "file.2";
        let destination: String = String::from(destination);

        file_access::write_string(&source, &"Hello, World!")?;
        file_access::rename(&source, &destination)?;

        // Clean-up:
        file_access::delete(&destination)?;
    })
}