pub struct Dir { /* private fields */ }dirfd)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.
#![feature(dirfd)]
use std::{fs::Dir, io};
fn main() -> std::io::Result<()> {
let dir = Dir::open("foo")?;
let mut file = dir.open_file("bar.txt")?;
let contents = io::read_to_string(file)?;
assert_eq!(contents, "Hello, world!");
Ok(())
}Implementations§
Source§impl Dir
impl Dir
Sourcepub fn open<P>(path: P) -> Result<Dir, Error>
🔬This is a nightly-only experimental API. (dirfd)
pub fn open<P>(path: P) -> Result<Dir, Error>
dirfd)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
#![feature(dirfd)]
use std::{fs::Dir, io};
fn main() -> std::io::Result<()> {
let dir = Dir::open("foo")?;
let mut f = dir.open_file("bar.txt")?;
let contents = io::read_to_string(f)?;
assert_eq!(contents, "Hello, world!");
Ok(())
}Sourcepub fn open_file<P>(&self, path: P) -> Result<File, Error>
🔬This is a nightly-only experimental API. (dirfd)
pub fn open_file<P>(&self, path: P) -> Result<File, Error>
dirfd)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
#![feature(dirfd)]
use std::{fs::Dir, io};
fn main() -> std::io::Result<()> {
let dir = Dir::open("foo")?;
let mut f = dir.open_file("bar.txt")?;
let contents = io::read_to_string(f)?;
assert_eq!(contents, "Hello, world!");
Ok(())
}Trait Implementations§
Source§impl AsFd for Dir
impl AsFd for Dir
Source§fn as_fd(&self) -> BorrowedFd<'_>
fn as_fd(&self) -> BorrowedFd<'_>
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> AggregateExpressionMethods for T
impl<T> AggregateExpressionMethods for T
Source§fn aggregate_distinct(self) -> Self::Outputwhere
Self: DistinctDsl,
fn aggregate_distinct(self) -> Self::Outputwhere
Self: DistinctDsl,
DISTINCT modifier for aggregate functions Read moreSource§fn aggregate_all(self) -> Self::Outputwhere
Self: AllDsl,
fn aggregate_all(self) -> Self::Outputwhere
Self: AllDsl,
ALL modifier for aggregate functions Read moreSource§fn aggregate_filter<P>(self, f: P) -> Self::Output
fn aggregate_filter<P>(self, f: P) -> Self::Output
Source§fn aggregate_order<O>(self, o: O) -> Self::Outputwhere
Self: OrderAggregateDsl<O>,
fn aggregate_order<O>(self, o: O) -> Self::Outputwhere
Self: OrderAggregateDsl<O>,
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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoSql for T
impl<T> IntoSql for T
Source§fn into_sql<T>(self) -> Self::Expression
fn into_sql<T>(self) -> Self::Expression
self to an expression for Diesel’s query builder. Read moreSource§fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
&self to an expression for Diesel’s query builder. Read moreSource§impl<Stream> IsTerminal for Streamwhere
Stream: AsFd,
impl<Stream> IsTerminal for Streamwhere
Stream: AsFd,
Source§fn is_terminal(&self) -> bool
fn is_terminal(&self) -> bool
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.