pub struct PkgName { /* private fields */ }Expand description
Parse a PKGNAME into its consituent parts.
In pkgsrc terminology a PKGNAME is made up of three parts:
PKGBASEcontains the name of the packagePKGVERSIONcontains the full version stringPKGREVISIONis an optional package revision denoted bynbfollowed by a number.
The name and version are split at the last -, and the revision, if
specified, should be located at the end of the version.
This module does not enforce strict formatting. If a PKGNAME is not well
formed then values may be empty or None.
§Examples
use pkgsrc::PkgName;
// A well formed package name.
let pkg = PkgName::new("mktool-1.3.2nb2");
assert_eq!(pkg.pkgname(), "mktool-1.3.2nb2");
assert_eq!(pkg.pkgbase(), "mktool");
assert_eq!(pkg.pkgversion(), "1.3.2nb2");
assert_eq!(pkg.pkgrevision(), Some(2));
// An invalid PKGREVISION that can likely only be created by accident.
let pkg = PkgName::new("mktool-1.3.2nb");
assert_eq!(pkg.pkgbase(), "mktool");
assert_eq!(pkg.pkgversion(), "1.3.2nb");
assert_eq!(pkg.pkgrevision(), Some(0));
// A "-" in the version causes an incorrect split.
let pkg = PkgName::new("mktool-1.3-2");
assert_eq!(pkg.pkgbase(), "mktool-1.3");
assert_eq!(pkg.pkgversion(), "2");
assert_eq!(pkg.pkgrevision(), None);
// Not well formed, but still accepted.
let pkg = PkgName::new("mktool");
assert_eq!(pkg.pkgbase(), "mktool");
assert_eq!(pkg.pkgversion(), "");
assert_eq!(pkg.pkgrevision(), None);
// Doesn't make any sense, but whatever!
let pkg = PkgName::new("1.0nb2");
assert_eq!(pkg.pkgbase(), "1.0nb2");
assert_eq!(pkg.pkgversion(), "");
assert_eq!(pkg.pkgrevision(), None);Implementations§
source§impl PkgName
impl PkgName
sourcepub fn pkgname(&self) -> &str
pub fn pkgname(&self) -> &str
Return a str reference containing the original PKGNAME used to
create this instance.
sourcepub fn pkgbase(&self) -> &str
pub fn pkgbase(&self) -> &str
Return a str reference containing the PKGBASE portion of the
package name, i.e. everything up to the final - and the version
number.
sourcepub fn pkgversion(&self) -> &str
pub fn pkgversion(&self) -> &str
Trait Implementations§
impl Eq for PkgName
impl StructuralPartialEq for PkgName
Auto Trait Implementations§
impl Freeze for PkgName
impl RefUnwindSafe for PkgName
impl Send for PkgName
impl Sync for PkgName
impl Unpin for PkgName
impl UnwindSafe for PkgName
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
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)
🔬This is a nightly-only experimental API. (
clone_to_uninit)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
Compare self to
key and return true if they are equal.