Skip to main content

Dir

Struct Dir 

Source
pub struct Dir { /* private fields */ }
Available on crate feature 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

Source

pub async fn open(path: impl AsRef<Path>) -> Result<Dir, Error>

Opens a directory at the specified path and returns a reference to it.

Source

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.

Source

pub async fn open_file(&self, path: impl AsRef<Path>) -> Result<File, Error>

Attempts to open a file in read-only mode.

Source

pub async fn create_file(&self, path: impl AsRef<Path>) -> Result<File, Error>

Opens a file in write-only mode.

Source

pub async fn open_dir(&self, path: impl AsRef<Path>) -> Result<Dir, Error>

Attempts to open a directory.

Source

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.

Source

pub async fn create_dir(&self, path: impl AsRef<Path>) -> Result<(), Error>

Creates a new, empty directory at the provided path.

Source

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.

Source

pub async fn dir_metadata(&self) -> Result<Metadata, Error>

Queries metadata about the underlying directory.

Source

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.

Query the metadata about a file without following symlinks.

Creates a new hard link on a filesystem.

Available on Unix only.

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.

Source

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.

Source

pub async fn remove_file(&self, path: impl AsRef<Path>) -> Result<(), Error>

Removes a file from a filesystem.

Source

pub async fn remove_dir(&self, path: impl AsRef<Path>) -> Result<(), Error>

Removes an empty directory.

Source

pub async fn read(&self, path: impl AsRef<Path>) -> Result<Vec<u8>, Error>

Read the entire contents of a file into a bytes vector.

Source

pub async fn write<B>(&self, path: impl AsRef<Path>, buf: B) -> BufResult<(), B>
where B: IoBuf,

Write a buffer as the entire contents of a file.

Trait Implementations§

Source§

impl AsFd for Dir

Available on Unix only.
Source§

fn as_fd(&self) -> BorrowedFd<'_>

Borrows the file descriptor. Read more
Source§

impl AsRawFd for Dir

Source§

fn as_raw_fd(&self) -> i32

Extracts the raw file descriptor. Read more
Source§

impl Clone for Dir

Source§

fn clone(&self) -> Dir

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Dir

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl FromRawFd for Dir

Available on Unix only.
Source§

unsafe fn from_raw_fd(fd: i32) -> Dir

Constructs a new instance of Self from the given raw file descriptor. Read more
Source§

impl ToSharedFd<File> for Dir

Source§

fn to_shared_fd(&self) -> SharedFd<File>

Return a cloned 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§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> AsSource for T
where T: AsFd,

§

fn source(&self) -> BorrowedFd<'_>

Returns the borrowed file descriptor.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> Ungil for T
where T: Send,