Skip to content

Commit ab066ae

Browse files
committed
add note about AlreadyExists to create_new
1 parent 9c9b568 commit ab066ae

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

library/std/src/fs.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,7 @@ impl File {
408408
///
409409
/// This function will create a file if it does not exist, or return an error if it does. This
410410
/// way, if the call succeeds, the file returned is guaranteed to be new.
411+
/// If a file exists at the target location before, creating file will fail with [`AlreadyExists`].
411412
///
412413
/// This option is useful because it is atomic. Otherwise between checking whether a file
413414
/// exists and creating a new one, the file may have been created by another process (a TOCTOU
@@ -416,6 +417,8 @@ impl File {
416417
/// This can also be written using
417418
/// `File::options().read(true).write(true).create_new(true).open(...)`.
418419
///
420+
/// [`AlreadyExists`]: crate::io::ErrorKind::AlreadyExists
421+
///
419422
/// # Examples
420423
///
421424
/// ```no_run
@@ -1071,6 +1074,7 @@ impl OpenOptions {
10711074
///
10721075
/// No file is allowed to exist at the target location, also no (dangling) symlink. In this
10731076
/// way, if the call succeeds, the file returned is guaranteed to be new.
1077+
/// If a file exists at the target location before, creating file will fail with [`AlreadyExists`].
10741078
///
10751079
/// This option is useful because it is atomic. Otherwise between checking
10761080
/// whether a file exists and creating a new one, the file may have been
@@ -1084,6 +1088,7 @@ impl OpenOptions {
10841088
///
10851089
/// [`.create()`]: OpenOptions::create
10861090
/// [`.truncate()`]: OpenOptions::truncate
1091+
/// [`AlreadyExists`]: io::ErrorKind::AlreadyExists
10871092
///
10881093
/// # Examples
10891094
///

0 commit comments

Comments
 (0)