pub struct Dir { /* private fields */ }dirfd #120426)Expand description
An object providing access to a directory on the filesystem.
Directories are automatically closed when they go out of scope. Errors detected
on closing are ignored by the implementation of Drop.
§Platform-specific behavior
On supported systems (including Windows and some UNIX-based OSes), this function acquires a
handle/file descriptor for the directory. This allows functions like Dir::open_file to
avoid TOCTOU errors when the directory itself is being moved.
On other systems, it stores an absolute path (see canonicalize()). In the latter case, no
TOCTOU guarantees are made.
§Examples
Opens a directory and then a file inside it.
Implementations§
Source§impl Dir
impl Dir
Sourcepub fn open<P: AsRef<Path>>(path: P) -> Result<Self>
🔬This is a nightly-only experimental API. (dirfd #120426)
pub fn open<P: AsRef<Path>>(path: P) -> Result<Self>
dirfd #120426)Attempts to open a directory at path in read-only mode.
§Errors
This function will return an error if path does not point to an existing directory.
Other errors may also be returned according to OpenOptions::open.
§Examples
Sourcepub fn open_file<P: AsRef<Path>>(&self, path: P) -> Result<File>
🔬This is a nightly-only experimental API. (dirfd #120426)
pub fn open_file<P: AsRef<Path>>(&self, path: P) -> Result<File>
dirfd #120426)Attempts to open a file in read-only mode relative to this directory.
§Errors
This function will return an error if path does not point to an existing file.
Other errors may also be returned according to OpenOptions::open.
§Examples
Trait Implementations§
Source§impl AsFd for Dir
impl AsFd for Dir
Source§fn as_fd(&self) -> BorrowedFd<'_>
fn as_fd(&self) -> BorrowedFd<'_>
target_os=trusty or WASI or target_os=motor only.