Struct Dir

Source
pub struct Dir { /* private fields */ }
Expand description

Represents a directory, which may be embedded or from the filesystem. Provides methods to enumerate and access files and subdirectories. Represents a directory, which may be embedded or from the filesystem. Provides methods to enumerate and access files and subdirectories.

Implementations§

Source§

impl Dir

Source

pub const fn from_embedded(dir: Dir<'static>, path: &'static str) -> Self

Creates a directory from an embedded include_dir::Dir and its root path. Intended for use in tests and advanced scenarios.

Source

pub fn from_path(path: &Path) -> Self

Creates a new directory from the given path, relative to the manifest directory at build time. The path can be any valid subdirectory or file path.

Source

pub fn into_dynamic(self) -> Self

Converts an embedded directory to a dynamic (filesystem-backed) directory if possible. For embedded directories, this will create a Path variant using the embedded root path.

Source

pub fn auto_dynamic(self) -> Self

Automatically converts to a dynamic directory if in debug mode (cfg!(debug_assertions)). In release mode, returns self unchanged.

Source

pub fn from_str(path: &'static str) -> Self

Creates a new root directory from the given string path, relative to the manifest directory. The path must be a string literal or static string.

Source

pub fn is_embedded(&self) -> bool

Returns true if this directory is embedded in the binary.

Source

pub fn path(&self) -> &Path

Returns the relative path of this directory.

Source

pub fn absolute_path(&self) -> &Path

Returns the absolute path of this directory.

Source

pub fn entries(&self) -> Vec<DirEntry>

Returns all immediate entries (files and subdirectories) in this directory.

Source

pub fn get_file(&self, name: &str) -> Option<File>

Returns the file with the given name if it exists in this directory. The name is relative to the directory root.

Source

pub fn get_dir(&self, name: &str) -> Option<Dir>

Returns a reference to the directory with the given name, if it exists.

Source

pub fn walk(&self) -> impl Iterator<Item = File>

Recursively walks all files in this directory and its subdirectories. Returns an iterator over all files found.

Trait Implementations§

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

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

impl Hash for Dir

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Dir

Source§

fn eq(&self, other: &Dir) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Dir

Source§

impl StructuralPartialEq for Dir

Auto Trait Implementations§

§

impl Freeze for Dir

§

impl RefUnwindSafe for Dir

§

impl Send for Dir

§

impl Sync for Dir

§

impl Unpin 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
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.

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> 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.