pub struct PkgPath { /* private fields */ }Expand description
Handling for PKGPATH metadata and relative package directory locations.
PkgPath is a struct for storing the path to a package within pkgsrc.
Binary packages contain the PKGPATH metadata, for example
pkgtools/pkg_install, while across pkgsrc dependencies are referred to by
their relative location, for example ../../pkgtools/pkg_install.
PkgPath takes either format as input, validates it for correctness,
then stores both internally as PathBuf entries.
Once stored, as_path returns the short path as a Path, while
as_full_path returns the full relative path as a Path.
As PkgPath uses PathBuf under the hood, there is a small amount of
normalisation performed, for example trailing or double slashes, but
otherwise input strings are expected to be precisely formatted, and a
PkgPathError is raised otherwise.
§Examples
use pkgsrc::PkgPath;
use std::ffi::OsStr;
let p = PkgPath::new("pkgtools/pkg_install").unwrap();
assert_eq!(p.as_path(), OsStr::new("pkgtools/pkg_install"));
assert_eq!(p.as_full_path(), OsStr::new("../../pkgtools/pkg_install"));
let p = PkgPath::new("../../pkgtools/pkg_install").unwrap();
assert_eq!(p.as_path(), OsStr::new("pkgtools/pkg_install"));
assert_eq!(p.as_full_path(), OsStr::new("../../pkgtools/pkg_install"));
// Missing category path.
assert!(PkgPath::new("../../pkg_install").is_err());
// Must traverse back to the pkgsrc root directory.
assert!(PkgPath::new("../pkg_install").is_err());
// Not fully formed.
assert!(PkgPath::new("/pkgtools/pkg_install").is_err());;Implementations§
source§impl PkgPath
impl PkgPath
sourcepub fn new(path: &str) -> Result<Self, PkgPathError>
pub fn new(path: &str) -> Result<Self, PkgPathError>
Create a new PkgPath
sourcepub fn as_path(&self) -> &Path
pub fn as_path(&self) -> &Path
Return a Path reference containing the short version of a PkgPath,
for example pkgtools/pkg_install.
sourcepub fn as_full_path(&self) -> &Path
pub fn as_full_path(&self) -> &Path
Return a Path reference containing the full version of a PkgPath,
for example ../../pkgtools/pkg_install.
Trait Implementations§
source§impl Ord for PkgPath
impl Ord for PkgPath
source§impl PartialOrd for PkgPath
impl PartialOrd for PkgPath
impl Eq for PkgPath
impl StructuralPartialEq for PkgPath
Auto Trait Implementations§
impl Freeze for PkgPath
impl RefUnwindSafe for PkgPath
impl Send for PkgPath
impl Sync for PkgPath
impl Unpin for PkgPath
impl UnwindSafe for PkgPath
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.