@@ -408,6 +408,9 @@ impl File {
408
408
///
409
409
/// This function will create a file if it does not exist, or return an error if it does. This
410
410
/// way, if the call succeeds, the file returned is guaranteed to be new.
411
+ /// If a file exists at the target location, creating a new file will fail with [`AlreadyExists`]
412
+ /// or another error based on the situation. See [`OpenOptions::open`] for a
413
+ /// non-exhaustive list of likely errors.
411
414
///
412
415
/// This option is useful because it is atomic. Otherwise between checking whether a file
413
416
/// exists and creating a new one, the file may have been created by another process (a TOCTOU
@@ -416,6 +419,8 @@ impl File {
416
419
/// This can also be written using
417
420
/// `File::options().read(true).write(true).create_new(true).open(...)`.
418
421
///
422
+ /// [`AlreadyExists`]: crate::io::ErrorKind::AlreadyExists
423
+ ///
419
424
/// # Examples
420
425
///
421
426
/// ```no_run
@@ -1071,6 +1076,9 @@ impl OpenOptions {
1071
1076
///
1072
1077
/// No file is allowed to exist at the target location, also no (dangling) symlink. In this
1073
1078
/// way, if the call succeeds, the file returned is guaranteed to be new.
1079
+ /// If a file exists at the target location, creating a new file will fail with [`AlreadyExists`]
1080
+ /// or another error based on the situation. See [`OpenOptions::open`] for a
1081
+ /// non-exhaustive list of likely errors.
1074
1082
///
1075
1083
/// This option is useful because it is atomic. Otherwise between checking
1076
1084
/// whether a file exists and creating a new one, the file may have been
@@ -1084,6 +1092,7 @@ impl OpenOptions {
1084
1092
///
1085
1093
/// [`.create()`]: OpenOptions::create
1086
1094
/// [`.truncate()`]: OpenOptions::truncate
1095
+ /// [`AlreadyExists`]: io::ErrorKind::AlreadyExists
1087
1096
///
1088
1097
/// # Examples
1089
1098
///
0 commit comments