pub struct Dir {
inner: Dir,
}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.
Fields§
§inner: Dirdirfd #120426)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.Auto Trait Implementations§
impl Freeze for Dir
impl RefUnwindSafe for Dir
impl Send for Dir
impl Sync for Dir
impl Unpin for Dir
impl UnsafeUnpin for Dir
impl UnwindSafe for Dir
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> SizedTypeProperties for T
impl<T> SizedTypeProperties for T
Source§#[doc(hidden)]const SIZE: usize = _
#[doc(hidden)]const SIZE: usize = _
sized_type_properties)Source§#[doc(hidden)]const ALIGN: usize = _
#[doc(hidden)]const ALIGN: usize = _
sized_type_properties)Source§#[doc(hidden)]const ALIGNMENT: Alignment = _
#[doc(hidden)]const ALIGNMENT: Alignment = _
ptr_alignment_type #102070)Source§#[doc(hidden)]const IS_ZST: bool = _
#[doc(hidden)]const IS_ZST: bool = _
sized_type_properties)Source§#[doc(hidden)]const LAYOUT: Layout = _
#[doc(hidden)]const LAYOUT: Layout = _
sized_type_properties)Source§#[doc(hidden)]const MAX_SLICE_LEN: usize = _
#[doc(hidden)]const MAX_SLICE_LEN: usize = _
sized_type_properties)[Self]. Read more