Expand description
PURL parsing, manipulation, and formatting.
A PURL is an identifier that refers to a software package. For example,
pkg:cargo/purl refers to this package.
This library supports PURLs at two levels:
- The shape and format of a PURL is implemented by
GenericPurl. It is possible to work with package-type-agnostic PURLs by using types likeGenericPurl<String>. (see also package-url/purl-spec#38) - The behavior of package types is implemented by
PackageTypeand combined withGenericPurlby the type aliasPurl. This implementation differs slightly from the PURL specification (seePackageTypefor details). It is possible to implement different package-type-specific behaviors or support for different package types by implementing thePurlShapetrait.
§Example
use std::str::FromStr;
use purl::GenericPurl;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let purl = GenericPurl::<String>::from_str(
"pkg:NPM/@acme/example@1.2.3?Checksum=sha256:\
E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855",
)?;
assert_eq!("npm", purl.package_type());
assert_eq!(Some("@acme"), purl.namespace());
assert_eq!("example", purl.name());
assert_eq!(Some("1.2.3"), purl.version());
// Normalization is performed during parsing.
assert_eq!(
"sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
purl.qualifiers()["checksum"],
);
assert_eq!(
"pkg:npm/%40acme/example@1.2.3?checksum=sha256:\
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
&purl.to_string(),
);
let purl = purl.into_builder().without_version().without_qualifier("checksum").build()?;
assert_eq!("pkg:npm/%40acme/example", &purl.to_string(),);
Ok(())
}§Features
- package-type:
PackageTypeand related types - serde: PURLs can be serialized and deserialized from strings
- smartstring: The smartstring crate is used to reduce heap allocations
Re-exports§
pub use qualifiers::Qualifiers;
Modules§
- qualifiers
- Specialized key-value collection for PURL qualifiers.
Structs§
- Generic
Purl - An immutable PURL.
- Generic
Purl Builder - A mutable, potentially invalid PURL.
- Purl
Parts - The parts that make up a PURL, minus the package type.
- Unsupported
Package Type package-type - An error that is returned when an unsupported package type is used.
Enums§
- Package
Error package-type - An error that is returned when working with
PackageType. - Package
Type package-type - The known package types.
- Parse
Error - An error returned when trying to parse an invalid PURL.
- Purl
Field - A specific, fixed field of a PURL.
Traits§
- Purl
Shape - A type that provides package-type-specific behavior.
Type Aliases§
- Purl
package-type - A PURL that supports the known package types.
- Purl
Builder package-type - A PURL builder that supports the known package types.
- Small
String smartstring - A string that may be stored inline instead of on the heap.