Struct nix::dir::Dir[][src]

pub struct Dir(_);

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 to fstat, openat, etc. The file descriptor continues to be owned by the Dir, so callers must not keep a RawFd after the Dir 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[src]

pub fn open<P: ?Sized + NixPath>(
    path: &P,
    oflag: OFlag,
    mode: Mode
) -> Result<Self>
[src]

Opens the given path as with fcntl::open.

pub fn openat<P: ?Sized + NixPath>(
    dirfd: RawFd,
    path: &P,
    oflag: OFlag,
    mode: Mode
) -> Result<Self>
[src]

Opens the given path as with fcntl::openat.

pub fn from<F: IntoRawFd>(fd: F) -> Result<Self>[src]

Converts from a descriptor-based object, closing the descriptor on success or failure.

pub fn from_fd(fd: RawFd) -> Result<Self>[src]

Converts from a file descriptor, closing it on success or failure.

pub fn iter(&mut self) -> Iter<'_>

Notable traits for Iter<'d>

impl<'d> Iterator for Iter<'d> type Item = Result<Entry>;
[src]

Returns an iterator of Result<Entry> which rewinds when finished.

Trait Implementations

impl AsRawFd for Dir[src]

impl Debug for Dir[src]

impl Drop for Dir[src]

impl Eq for Dir[src]

impl Hash for Dir[src]

impl IntoIterator for Dir[src]

type Item = Result<Entry>

The type of the elements being iterated over.

type IntoIter = OwningIter

Which kind of iterator are we turning this into?

fn into_iter(self) -> Self::IntoIter[src]

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 PartialEq<Dir> for Dir[src]

impl Send for Dir[src]

impl StructuralEq for Dir[src]

impl StructuralPartialEq for Dir[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.