pub struct Purl { /* private fields */ }Expand description
A parsed Package URL. Holds the original text and never rewrites it.
Experimental: may change in a 0.x minor release.
Equality compares the original text and components exactly. To ask
whether two spellings name the same package, compare
Purl::canonical values or use same_package_url.
use libtea_core::purl::{same_package_url, Purl};
let a = Purl::parse("PKG:Maven/org.apache/commons-io@2.11.0?Type=jar&classifier=").unwrap();
let b = Purl::parse("pkg:maven/org.apache/commons-io@2.11.0?type=jar").unwrap();
assert_eq!(a.as_str(), "PKG:Maven/org.apache/commons-io@2.11.0?Type=jar&classifier=");
assert_eq!(a.canonical().as_str(), "pkg:maven/org.apache/commons-io@2.11.0?type=jar");
assert!(same_package_url(&a, &b));Implementations§
Source§impl Purl
impl Purl
Sourcepub fn parse(text: &str) -> Result<Self, PurlError>
pub fn parse(text: &str) -> Result<Self, PurlError>
Parse a Package URL as ECMA-427 describes, right to left.
Accepts what the specification says a parser should accept, such as
pkg:// and redundant slashes, and keeps text unchanged for
Self::as_str.
§Errors
Returns PurlError when a required component is missing, a type or
qualifier key has characters ECMA-427 does not allow, a qualifier key
repeats, a decoded namespace or subpath segment contains /, the
percent-encoding is invalid, or the text or its canonical form is
longer than MAX_PURL_BYTES.
Sourcepub fn package_type(&self) -> &str
pub fn package_type(&self) -> &str
The type, lowercased.
Sourcepub fn namespace(&self) -> Option<String>
pub fn namespace(&self) -> Option<String>
The decoded namespace segments joined with /, or None when there
are none. No type-specific normalization is applied.
Sourcepub fn qualifiers(&self) -> impl Iterator<Item = (&str, &str)>
pub fn qualifiers(&self) -> impl Iterator<Item = (&str, &str)>
Decoded qualifiers with non-empty values, keys lowercased, in key order.
Sourcepub fn qualifier(&self, key: &str) -> Option<&str>
pub fn qualifier(&self, key: &str) -> Option<&str>
The decoded value of one qualifier; key is matched in lowercase.
Sourcepub fn subpath(&self) -> Option<String>
pub fn subpath(&self) -> Option<String>
The decoded subpath segments joined with /, without empty, . and
.. segments, or None when none remain.
Sourcepub fn canonical(&self) -> CanonicalPurl
pub fn canonical(&self) -> CanonicalPurl
The canonical form under PurlRules::Generic.