Struct nix::dir::Dir
pub struct Dir(_);
Documentation
An open directory.
This is a lower-level interface than std::fs::ReadDir
. Notable differences:
- can be opened from a file descriptor (as returned by
openat
, perhaps before knowing if the path represents a file or directory). - implements
AsRawFd
, so it can be passed tofstat
,openat
, etc. The file descriptor continues to be owned by theDir
, so callers must not keep aRawFd
after theDir
is dropped. - can be iterated through multiple times without closing and reopening the file descriptor. Each iteration rewinds when finished.
- returns entries for
.
(current directory) and..
(parent directory). - returns entries’ names as a
CStr
(no allocation or conversion beyond whatever libc does).
Implementations
impl Dir
Trait Implementations
impl Debug for Dir
fn fmt(&Self, f: &mut $crate::fmt::Formatter<'_>) -> $crate::fmt::Result
impl Hash for Dir
fn hash<__H: $crate::hash::Hasher>(&Self, state: &mut __H) -> ()
impl IntoIterator for Dir
type IntoIter = OwningIter
fn into_iter(Self) -> Self::IntoIter
Creates a owning iterator, that is, one that takes ownership of the
Dir
. The Dir
cannot be used after calling this. This can be useful
when you have a function that both creates a Dir
instance and returns
an Iterator
.
Example:
use nix::{dir::Dir, fcntl::OFlag, sys::stat::Mode};
use std::{iter::Iterator, string::String};
fn ls_upper(dirname: &str) -> impl Iterator<Item=String> {
let d = Dir::open(dirname, OFlag::O_DIRECTORY, Mode::S_IXUSR).unwrap();
d.into_iter().map(|x| x.unwrap().file_name().as_ref().to_string_lossy().to_ascii_uppercase())
}
impl StructuralEq for Dir
impl StructuralPartialEq for Dir
Auto Trait Implementations
impl RefUnwindSafe for Dir
impl UnwindSafe for Dir
Blanket Implementations
impl<T> BorrowMut<T> for T
where
T: ?Sized,
where
T: ?Sized,
fn borrow_mut(&mut Self) -> &mut T