Skip to content

Commit 35f176b

Browse files
committed
Clarify that std::fs::rename can move
Fixes rust-lang#24816
1 parent 2f613bf commit 35f176b

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/libstd/fs.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,9 @@ pub fn symlink_metadata<P: AsRef<Path>>(path: P) -> io::Result<Metadata> {
844844

845845
/// Rename a file or directory to a new name.
846846
///
847+
/// Moving a file or directory is also a rename, in a sense, and so this
848+
/// function is not limited a single directory.
849+
///
847850
/// # Errors
848851
///
849852
/// This function will return an error if the provided `from` doesn't exist, if
@@ -861,6 +864,17 @@ pub fn symlink_metadata<P: AsRef<Path>>(path: P) -> io::Result<Metadata> {
861864
/// # Ok(())
862865
/// # }
863866
/// ```
867+
///
868+
/// Moving:
869+
///
870+
/// ```
871+
/// use std::fs;
872+
///
873+
/// # fn foo() -> std::io::Result<()> {
874+
/// try!(fs::rename("from/a.txt", "to/b.txt"));
875+
/// # Ok(())
876+
/// # }
877+
/// ```
864878
#[stable(feature = "rust1", since = "1.0.0")]
865879
pub fn rename<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> io::Result<()> {
866880
fs_imp::rename(from.as_ref(), to.as_ref())

0 commit comments

Comments
 (0)