pub struct WithLocal { /* private fields */ }Expand description
Stores both the normal and local form a configuration path.
The local form has .local inserted just before the extension: cli-app.kdl has the local form
cli-app.local.kdl.
While this is mostly intended for file, nothing precludes an application from using it for directories.
use std::path::{Path, PathBuf};
use config_finder::WithLocal;
// `.local` is inserted before the extension for the `.local_path()` form
let wl = WithLocal::new("cli-app", "kdl");
assert_eq!(wl.path(), Path::new("cli-app.kdl"));
assert_eq!(wl.local_path(), Path::new("cli-app.local.kdl"));
// Even if the extension is empty (can notably be used for directories)
let wl = WithLocal::new("cli-app", "");
assert_eq!(wl.path(), Path::new("cli-app"));
assert_eq!(wl.local_path(), Path::new("cli-app.local"));
// An empty base is valid too
let wl = WithLocal::new("", "kdl");
assert_eq!(wl.path(), Path::new(".kdl"));
assert_eq!(wl.local_path(), Path::new(".local.kdl"));
// If you need to store a form (local or not),
let wl = WithLocal::new("zellij", "kdl");
assert_eq!(wl.into_paths(), (PathBuf::from("zellij.kdl"), PathBuf::from("zellij.local.kdl")));Implementations§
Source§impl WithLocal
impl WithLocal
Sourcepub fn new(base: impl Into<OsString>, ext: impl AsRef<OsStr>) -> Self
pub fn new(base: impl Into<OsString>, ext: impl AsRef<OsStr>) -> Self
Computes both the normal and local forms of the path.
If the extension is non-empty, inserts a dot (.) between the base and the extension.
Sourcepub fn local_path(&self) -> &Path
pub fn local_path(&self) -> &Path
Path with the added .local just before the extension.
Sourcepub fn into_paths(self) -> (PathBuf, PathBuf)
pub fn into_paths(self) -> (PathBuf, PathBuf)
Destructure into the inner (path, local_path) without allocating.
Trait Implementations§
impl Eq for WithLocal
impl StructuralPartialEq for WithLocal
Auto Trait Implementations§
impl Freeze for WithLocal
impl RefUnwindSafe for WithLocal
impl Send for WithLocal
impl Sync for WithLocal
impl Unpin for WithLocal
impl UnwindSafe for WithLocal
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