Skip to content

Commit 71252d9

Browse files
committed
Document possible io::ErrorKinds of fs::open
Try to make clear that this isn't an API guarantee for now, as we likely want to refine these errors in the future, e.g. `ENOSPC` "No space left on device". CC #40322
1 parent f590a44 commit 71252d9

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

src/libstd/fs.rs

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -653,15 +653,29 @@ impl OpenOptions {
653653
/// # Errors
654654
///
655655
/// This function will return an error under a number of different
656-
/// circumstances, to include but not limited to:
657-
///
658-
/// * Opening a file that does not exist without setting `create` or
659-
/// `create_new`.
660-
/// * Attempting to open a file with access that the user lacks
661-
/// permissions for
662-
/// * Filesystem-level errors (full disk, etc)
663-
/// * Invalid combinations of open options (truncate without write access,
664-
/// no access mode set, etc)
656+
/// circumstances. Some of these error conditions are listed here, together
657+
/// with their [`ErrorKind`]. The mapping to `ErrorKind`s is not part of
658+
/// the compatiblity contract of the function, especially the `Other` kind
659+
/// might change to more specific kinds in the future.
660+
///
661+
/// * `NotFound`: The specified file does not exist and neither `create` or
662+
/// `create_new` is set,
663+
/// * `NotFound`: One of the directory components of the file path does not
664+
/// exist.
665+
/// * `PermissionDenied`: The user lacks permission to get the specified
666+
/// access rights for the file.
667+
/// * `PermissionDenied`: The user lacks permission to open one of the
668+
/// directory components of the specified path.
669+
/// * `AlreadyExists`: `create_new` was specified and the file already
670+
/// exists.
671+
/// * `InvalidInput`: Invalid combinations of open options (truncate
672+
/// without write access, no access mode set, etc.).
673+
/// * `Other`: One of the directory components of the specified file path
674+
/// was not, in fact, a directory.
675+
/// * `Other`: Filesystem-level errors: full disk, write permission
676+
/// requested on a read-only file system, exceeded disk quota, too many
677+
/// open files, too long filename, too many symbolic links in the
678+
/// specified path (Unix-like systems only), etc.
665679
///
666680
/// # Examples
667681
///
@@ -670,6 +684,8 @@ impl OpenOptions {
670684
///
671685
/// let file = OpenOptions::new().open("foo.txt");
672686
/// ```
687+
///
688+
/// [`ErrorKind`]: ../io/enum.ErrorKind.html
673689
#[stable(feature = "rust1", since = "1.0.0")]
674690
pub fn open<P: AsRef<Path>>(&self, path: P) -> io::Result<File> {
675691
self._open(path.as_ref())

0 commit comments

Comments
 (0)