Crates.io | purl |
lib.rs | purl |
version | |
source | src |
created_at | 2023-06-26 21:00:16.929894+00 |
updated_at | 2024-12-17 22:44:32.747223+00 |
description | A Package URL implementation with customizable package types |
homepage | |
repository | https://github.com/phylum-dev/purl/ |
max_upload_size | |
id | 900669 |
Cargo.toml error: | TOML parse error at line 17, column 1 | 17 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
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:
GenericPurl
. It is possible to work with package-type-agnostic PURLs by using types like GenericPurl<String>
. (see also package-url/purl-spec#38)PackageType
and combined with GenericPurl
by the type alias Purl
. This implementation differs slightly from the PURL specification (see PackageType
for details). It is possible to implement different package-type-specific behaviors or support for different package types by implementing the PurlShape
trait.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(())
}
PackageType
and related types