pub struct GetDir {
pub dir: PathBuf,
pub depth: usize,
pub targets: Vec<Target>,
}Expand description
Utility to get directory.
§Example
use std::path::PathBuf;
use get_dir::{
GetDir,
Target,
DirTarget,
};
let path: PathBuf = GetDir::new()
.target(
Target::Dir(DirTarget::new("src")),
)
.run()
.unwrap();Fields§
§dir: PathBufThe directory to run the process.
depth: usizeThe depth of the search.
targets: Vec<Target>The targets to search.
Implementations§
Source§impl GetDir
impl GetDir
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new GetDir instance.
§Example
use std::path::PathBuf;
use get_dir::GetDir;
let path: PathBuf = GetDir::new()
.run()
.unwrap();Sourcepub fn directory<D: Into<PathBuf>>(self, dir: D) -> Self
pub fn directory<D: Into<PathBuf>>(self, dir: D) -> Self
Specific the directory to run the process.
By default, it runs in current directory.
§Example
use std::path::{
Path,
PathBuf,
};
use get_dir::GetDir;
let path: PathBuf = GetDir::new()
.directory(Path::new(".").join("src"))
.run()
.unwrap();Sourcepub fn dir<D: Into<PathBuf>>(self, dir: D) -> Self
pub fn dir<D: Into<PathBuf>>(self, dir: D) -> Self
Alias for GetDir::directory function.
Sourcepub fn depth(self, depth: usize) -> Self
pub fn depth(self, depth: usize) -> Self
Set the depth of the search.
By default, it is usize::MAX.
§Example
use std::path::PathBuf;
use get_dir::GetDir;
let path: PathBuf = GetDir::new()
.depth(2)
.run()
.unwrap();Sourcepub fn targets<TS, T>(self, targets: TS) -> Self
pub fn targets<TS, T>(self, targets: TS) -> Self
Add targets to the search.
§Example
use std::path::PathBuf;
use get_dir::{
GetDir,
Target,
DirTarget,
FileTarget,
};
let path: PathBuf = GetDir::new()
.targets([
Target::Dir(DirTarget::new("src")),
Target::File(FileTarget::new("Cargo.toml")),
])
.run()
.unwrap();Sourcepub fn target(self, target: Target) -> Self
pub fn target(self, target: Target) -> Self
Add a target to the search.
§Example
use std::path::PathBuf;
use get_dir::{
GetDir,
Target,
DirTarget,
};
let path: PathBuf = GetDir::new()
.target(Target::Dir(DirTarget::new("src")))
.run()
.unwrap();Sourcepub fn run(self) -> Result<PathBuf>
pub fn run(self) -> Result<PathBuf>
Get the first directory containing any of the specified targets.
§Example
use std::path::PathBuf;
use get_dir::GetDir;
let path: PathBuf = GetDir::new()
.run()
.unwrap();Sourcepub fn run_reverse(self) -> Result<PathBuf>
pub fn run_reverse(self) -> Result<PathBuf>
Get the first directory containing any of the specified targets in reverse.
§Example
use std::path::PathBuf;
use get_dir::GetDir;
let path: PathBuf = GetDir::new()
.run_reverse()
.unwrap();Trait Implementations§
Source§impl GetDirAsyncExt for GetDir
impl GetDirAsyncExt for GetDir
Source§impl GetDirAsyncExt for GetDir
impl GetDirAsyncExt for GetDir
Auto Trait Implementations§
impl Freeze for GetDir
impl RefUnwindSafe for GetDir
impl Send for GetDir
impl Sync for GetDir
impl Unpin for GetDir
impl UnwindSafe for GetDir
Blanket Implementations§
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
Mutably borrows from an owned value. Read more