pub struct PkgName { /* private fields */ }Expand description
Parse a PKGNAME into its constituent 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
Sourcepub fn pkgversion_norev(&self) -> &str
pub fn pkgversion_norev(&self) -> &str
Return a str reference containing the PKGVERSION_NOREV of the
package name, i.e. the version with any nb<x> revision marker
stripped.
Sourcepub fn pkgrevision(&self) -> Option<i64>
pub fn pkgrevision(&self) -> Option<i64>
Return the PKGREVISION of the package name. See pkgrevision
for the parsing rules.
Trait Implementations§
Source§impl Ord for PkgName
impl Ord for PkgName
Source§impl PartialOrd for PkgName
impl PartialOrd for PkgName
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 UnsafeUnpin 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.