packageurl
Read and generate Package URLs in Rust.
This crate is an implementation of the Package URL specification for the Rust programming language.
Add this crate to the Cargo.toml
:
toml
[dependencies]
packageurl = "^0.2.0"
Parse a string containing a raw PURL using the
FromStr
trait:
```rust extern crate packageurl use std::str::FromStr; use packageurl::PackageUrl;
let purl = PackageUrl::from_str("pkg:cargo/packageurl@0.2.0") ```
Generate a canonical PURL using the
ToString
trait:
```rust extern crate packageurl; use std::string::ToString; use package::PackageUrl;
let canonical = PackageUrl::new("cargo", "packageurl") .withversion("0.2.0") .tostring(); ```
See more in the online documentation.
The specification is not completely enforced right now: in particular, it will allow building Package URLs with invalid namespaces and the like. More validations and errors are to be added in the future.