pub struct Dir { /* private fields */ }fs only.Expand description
A reference to an open directory on a filesystem.
§Platform specific
- Windows: the operations are forwarded to
cap-primitives. They will treat self as the root of the filesystem. - Unix: the operatiosn are forwarded to syscalls directly. They don’t limit the path to be under self. If the path is absolute, the directory represented by self will be ignored.
Implementations§
Source§impl Dir
impl Dir
Sourcepub async fn open(path: impl AsRef<Path>) -> Result<Dir, Error>
pub async fn open(path: impl AsRef<Path>) -> Result<Dir, Error>
Opens a directory at the specified path and returns a reference to it.
Sourcepub async fn open_file_with(
&self,
path: impl AsRef<Path>,
options: &OpenOptions,
) -> Result<File, Error>
pub async fn open_file_with( &self, path: impl AsRef<Path>, options: &OpenOptions, ) -> Result<File, Error>
Opens a file at path with the options specified by options.
Sourcepub async fn open_file(&self, path: impl AsRef<Path>) -> Result<File, Error>
pub async fn open_file(&self, path: impl AsRef<Path>) -> Result<File, Error>
Attempts to open a file in read-only mode.
Sourcepub async fn create_file(&self, path: impl AsRef<Path>) -> Result<File, Error>
pub async fn create_file(&self, path: impl AsRef<Path>) -> Result<File, Error>
Opens a file in write-only mode.
Sourcepub async fn open_dir(&self, path: impl AsRef<Path>) -> Result<Dir, Error>
pub async fn open_dir(&self, path: impl AsRef<Path>) -> Result<Dir, Error>
Attempts to open a directory.
Sourcepub async fn create_dir_with(
&self,
path: impl AsRef<Path>,
builder: &DirBuilder,
) -> Result<(), Error>
pub async fn create_dir_with( &self, path: impl AsRef<Path>, builder: &DirBuilder, ) -> Result<(), Error>
Creates the specified directory with the options configured in this builder.
Sourcepub async fn create_dir(&self, path: impl AsRef<Path>) -> Result<(), Error>
pub async fn create_dir(&self, path: impl AsRef<Path>) -> Result<(), Error>
Creates a new, empty directory at the provided path.
Sourcepub async fn create_dir_all(&self, path: impl AsRef<Path>) -> Result<(), Error>
pub async fn create_dir_all(&self, path: impl AsRef<Path>) -> Result<(), Error>
Recursively create a directory and all of its parent components if they are missing.
Sourcepub async fn dir_metadata(&self) -> Result<Metadata, Error>
pub async fn dir_metadata(&self) -> Result<Metadata, Error>
Queries metadata about the underlying directory.
Sourcepub async fn metadata(&self, path: impl AsRef<Path>) -> Result<Metadata, Error>
pub async fn metadata(&self, path: impl AsRef<Path>) -> Result<Metadata, Error>
Given a path, query the file system to get information about a file, directory, etc.
Sourcepub async fn symlink_metadata(
&self,
path: impl AsRef<Path>,
) -> Result<Metadata, Error>
pub async fn symlink_metadata( &self, path: impl AsRef<Path>, ) -> Result<Metadata, Error>
Query the metadata about a file without following symlinks.
Sourcepub async fn hard_link(
&self,
source: impl AsRef<Path>,
target_dir: &Dir,
target: impl AsRef<Path>,
) -> Result<(), Error>
pub async fn hard_link( &self, source: impl AsRef<Path>, target_dir: &Dir, target: impl AsRef<Path>, ) -> Result<(), Error>
Creates a new hard link on a filesystem.
Sourcepub async fn symlink(
&self,
original: impl AsRef<Path>,
link: impl AsRef<Path>,
) -> Result<(), Error>
Available on Unix only.
pub async fn symlink( &self, original: impl AsRef<Path>, link: impl AsRef<Path>, ) -> Result<(), Error>
Creates a new symbolic link on a filesystem.
The original argument provides the target of the symlink. The link
argument provides the name of the created symlink.
Despite the argument ordering, original is not resolved relative to
self here. link is resolved relative to self, and original is
not resolved within this function.
Sourcepub async fn rename(
&self,
from: impl AsRef<Path>,
to_dir: &Dir,
to: impl AsRef<Path>,
) -> Result<(), Error>
pub async fn rename( &self, from: impl AsRef<Path>, to_dir: &Dir, to: impl AsRef<Path>, ) -> Result<(), Error>
Rename a file or directory to a new name, replacing the original file if it already exists.
Sourcepub async fn remove_file(&self, path: impl AsRef<Path>) -> Result<(), Error>
pub async fn remove_file(&self, path: impl AsRef<Path>) -> Result<(), Error>
Removes a file from a filesystem.
Sourcepub async fn remove_dir(&self, path: impl AsRef<Path>) -> Result<(), Error>
pub async fn remove_dir(&self, path: impl AsRef<Path>) -> Result<(), Error>
Removes an empty directory.
Trait Implementations§
Source§impl AsFd for Dir
Available on Unix only.
impl AsFd for Dir
Source§fn as_fd(&self) -> BorrowedFd<'_>
fn as_fd(&self) -> BorrowedFd<'_>
SharedFd.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§
§impl<T> AsSource for Twhere
T: AsFd,
impl<T> AsSource for Twhere
T: AsFd,
§fn source(&self) -> BorrowedFd<'_>
fn source(&self) -> BorrowedFd<'_>
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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 more