pub struct GenPath;Expand description
Helper for building paths from the current process location.
Implementations§
Source§impl GenPath
impl GenPath
Sourcepub fn from_working_dir(steps: i32) -> Result<PathBuf, DatabaseError>
pub fn from_working_dir(steps: i32) -> Result<PathBuf, DatabaseError>
Returns the working directory, with steps parts removed from the end.
§Parameters
steps: number of path parts at the end to remove.
§Errors
Returns an error if:
- the current directory cannot be read,
stepsis greater than or equal to the number of removable segments.
§Examples
use file_database::{DatabaseError, GenPath};
fn main() -> Result<(), DatabaseError> {
let _cwd = GenPath::from_working_dir(0)?;
Ok(())
}Sourcepub fn from_exe(steps: i32) -> Result<PathBuf, DatabaseError>
pub fn from_exe(steps: i32) -> Result<PathBuf, DatabaseError>
Returns the executable directory, with steps parts removed from the end.
§Parameters
steps: number of path parts at the end to remove from the executable directory.
§Errors
Returns an error if:
- the executable path cannot be read,
stepsis too large for the path depth.
§Examples
use file_database::{DatabaseError, GenPath};
fn main() -> Result<(), DatabaseError> {
let _exe_dir = GenPath::from_exe(0)?;
Ok(())
}Sourcepub fn from_closest_match(
name: impl AsRef<Path>,
) -> Result<PathBuf, DatabaseError>
pub fn from_closest_match( name: impl AsRef<Path>, ) -> Result<PathBuf, DatabaseError>
Looks for the nearest matching folder name while walking up from the executable.
At each level, this checks:
- the folder name itself,
- child folders one level down.
File entries are ignored.
§Parameters
name: directory name to search for.
§Errors
Returns an error if:
- no matching directory is found,
- the provided name cannot be converted from
OsStrtoString.
§Examples
use file_database::{DatabaseError, GenPath};
fn main() -> Result<(), DatabaseError> {
let _path = GenPath::from_closest_match("src")?;
Ok(())
}Trait Implementations§
impl StructuralPartialEq for GenPath
Auto Trait Implementations§
impl Freeze for GenPath
impl RefUnwindSafe for GenPath
impl Send for GenPath
impl Sync for GenPath
impl Unpin for GenPath
impl UnsafeUnpin for GenPath
impl UnwindSafe for GenPath
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