pub struct PathResolver { /* private fields */ }Expand description
Configurable path resolver for a specific project/domain.
Implementations§
Source§impl PathResolver
impl PathResolver
Sourcepub fn new(project_name: &str) -> Self
pub fn new(project_name: &str) -> Self
Create a new resolver for the given project name.
The project name is converted to an environment variable prefix:
- “music-theory” → “MUSIC_THEORY”
- “my_project” → “MY_PROJECT”
Sourcepub fn with_config_marker(self, marker: &str) -> Self
pub fn with_config_marker(self, marker: &str) -> Self
Set the marker file/directory that identifies a config directory.
Sourcepub fn with_project_markers(self, markers: &[&str]) -> Self
pub fn with_project_markers(self, markers: &[&str]) -> Self
Set marker files that identify the project root.
Sourcepub fn with_config_fallback(self, path: &str) -> Self
pub fn with_config_fallback(self, path: &str) -> Self
Set a fallback path for config directory (supports ~ expansion).
Sourcepub fn with_project_fallback(self, path: &str) -> Self
pub fn with_project_fallback(self, path: &str) -> Self
Set a fallback path for project root (supports ~ expansion).
Sourcepub fn env_var(&self, suffix: &str) -> String
pub fn env_var(&self, suffix: &str) -> String
Get the environment variable name for a given suffix.
§Example
use fabryk_core::util::resolver::PathResolver;
let resolver = PathResolver::new("music-theory");
assert_eq!(resolver.env_var("CONFIG_DIR"), "MUSIC_THEORY_CONFIG_DIR");Sourcepub fn config_dir(&self) -> Option<PathBuf>
pub fn config_dir(&self) -> Option<PathBuf>
Resolve the config directory.
Checks in order:
{PROJECT}_CONFIG_DIRenvironment variable- Walk up from binary looking for config marker
- Fallback path (if configured)
Sourcepub fn project_root(&self) -> Option<PathBuf>
pub fn project_root(&self) -> Option<PathBuf>
Resolve the project root directory.
Checks in order:
{PROJECT}_ROOTenvironment variable- Walk up from binary looking for project markers
- Fallback path (if configured)
Sourcepub fn project_name(&self) -> &str
pub fn project_name(&self) -> &str
Get the project name.
Sourcepub fn env_prefix(&self) -> &str
pub fn env_prefix(&self) -> &str
Get the environment variable prefix.
Trait Implementations§
Source§impl Clone for PathResolver
impl Clone for PathResolver
Source§fn clone(&self) -> PathResolver
fn clone(&self) -> PathResolver
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for PathResolver
impl RefUnwindSafe for PathResolver
impl Send for PathResolver
impl Sync for PathResolver
impl Unpin for PathResolver
impl UnsafeUnpin for PathResolver
impl UnwindSafe for PathResolver
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