add note about AlreadyExists to create_new

This commit is contained in:
anatawa12 2024-05-06 09:52:13 +09:00
parent 9c9b568792
commit ab066ae329
No known key found for this signature in database
GPG Key ID: 9CA909848B8E4EA6

View File

@ -408,6 +408,7 @@ impl File {
/// ///
/// This function will create a file if it does not exist, or return an error if it does. This /// This function will create a file if it does not exist, or return an error if it does. This
/// way, if the call succeeds, the file returned is guaranteed to be new. /// way, if the call succeeds, the file returned is guaranteed to be new.
/// If a file exists at the target location before, creating file will fail with [`AlreadyExists`].
/// ///
/// This option is useful because it is atomic. Otherwise between checking whether a file /// This option is useful because it is atomic. Otherwise between checking whether a file
/// exists and creating a new one, the file may have been created by another process (a TOCTOU /// exists and creating a new one, the file may have been created by another process (a TOCTOU
@ -416,6 +417,8 @@ impl File {
/// This can also be written using /// This can also be written using
/// `File::options().read(true).write(true).create_new(true).open(...)`. /// `File::options().read(true).write(true).create_new(true).open(...)`.
/// ///
/// [`AlreadyExists`]: crate::io::ErrorKind::AlreadyExists
///
/// # Examples /// # Examples
/// ///
/// ```no_run /// ```no_run
@ -1071,6 +1074,7 @@ impl OpenOptions {
/// ///
/// No file is allowed to exist at the target location, also no (dangling) symlink. In this /// No file is allowed to exist at the target location, also no (dangling) symlink. In this
/// way, if the call succeeds, the file returned is guaranteed to be new. /// way, if the call succeeds, the file returned is guaranteed to be new.
/// If a file exists at the target location before, creating file will fail with [`AlreadyExists`].
/// ///
/// This option is useful because it is atomic. Otherwise between checking /// This option is useful because it is atomic. Otherwise between checking
/// whether a file exists and creating a new one, the file may have been /// whether a file exists and creating a new one, the file may have been
@ -1084,6 +1088,7 @@ impl OpenOptions {
/// ///
/// [`.create()`]: OpenOptions::create /// [`.create()`]: OpenOptions::create
/// [`.truncate()`]: OpenOptions::truncate /// [`.truncate()`]: OpenOptions::truncate
/// [`AlreadyExists`]: io::ErrorKind::AlreadyExists
/// ///
/// # Examples /// # Examples
/// ///