pub struct Purl {
pub purl_type: String,
pub namespace: Option<String>,
pub name: String,
pub version: Option<String>,
}Expand description
A Package URL builder for creating valid PURL strings.
PURLs are a standardized way to identify software packages across different ecosystems. This struct provides a builder pattern for constructing valid PURL strings.
§Format
pkg:type/namespace/name@version?qualifiers#subpath- type (required): Package ecosystem (npm, maven, pypi, etc.)
- namespace (optional): Package scope/group (e.g., Maven groupId, npm scope)
- name (required): Package name
- version (optional): Specific version
§Example
use vulnera_advisor::Purl;
// Scoped npm package
let purl = Purl::new("npm", "core")
.with_namespace("@angular")
.with_version("12.0.0")
.to_string();
assert_eq!(purl, "pkg:npm/%40angular/core@12.0.0");Fields§
§purl_type: StringPackage type (ecosystem).
namespace: Option<String>Optional namespace (e.g., Maven groupId, npm scope).
name: StringPackage name.
version: Option<String>Optional version.
Implementations§
Source§impl Purl
impl Purl
Sourcepub fn new(ecosystem: impl Into<String>, name: impl Into<String>) -> Self
pub fn new(ecosystem: impl Into<String>, name: impl Into<String>) -> Self
Create a new PURL with the given ecosystem and package name.
The ecosystem is automatically mapped to the correct PURL type (e.g., “crates.io” → “cargo”, “PyPI” → “pypi”).
§Arguments
ecosystem- The package ecosystem (e.g., “npm”, “crates.io”, “PyPI”)name- The package name
§Example
use vulnera_advisor::Purl;
let purl = Purl::new("crates.io", "serde");
assert_eq!(purl.purl_type, "cargo");Sourcepub fn new_validated(
ecosystem: impl Into<String>,
name: impl Into<String>,
) -> Result<Self, PurlError>
pub fn new_validated( ecosystem: impl Into<String>, name: impl Into<String>, ) -> Result<Self, PurlError>
Create a new PURL with validation.
Returns an error if the ecosystem is not in the known list.
§Example
use vulnera_advisor::Purl;
// Valid ecosystem
let purl = Purl::new_validated("npm", "lodash").unwrap();
// Invalid ecosystem
let result = Purl::new_validated("invalid", "package");
assert!(result.is_err());Sourcepub fn is_known_ecosystem(purl_type: &str) -> bool
pub fn is_known_ecosystem(purl_type: &str) -> bool
Check if an ecosystem type is in the known list.
Sourcepub fn with_namespace(self, namespace: impl Into<String>) -> Self
pub fn with_namespace(self, namespace: impl Into<String>) -> Self
Add a namespace (e.g., Maven groupId, npm scope like “@angular”).
Sourcepub fn with_version(self, version: impl Into<String>) -> Self
pub fn with_version(self, version: impl Into<String>) -> Self
Add a version.
Sourcepub fn parse(s: &str) -> Result<Self, PurlError>
pub fn parse(s: &str) -> Result<Self, PurlError>
Parse a PURL string into a Purl struct.
§Example
use vulnera_advisor::Purl;
let purl = Purl::parse("pkg:npm/lodash@4.17.20").unwrap();
assert_eq!(purl.purl_type, "npm");
assert_eq!(purl.name, "lodash");
assert_eq!(purl.version, Some("4.17.20".to_string()));Sourcepub fn ecosystem(&self) -> String
pub fn ecosystem(&self) -> String
Get the ecosystem name (reverse mapping from PURL type).
Returns the common ecosystem name for known mappings, or the PURL type itself if no mapping exists.
Sourcepub fn cache_key(&self) -> String
pub fn cache_key(&self) -> String
Generate a hash suitable for use as a cache key.
This creates a deterministic hash of the PURL for use in Redis cache keys.
Sourcepub fn cache_key_from_str(purl: &str) -> String
pub fn cache_key_from_str(purl: &str) -> String
Generate a cache key from a PURL string.
Trait Implementations§
impl Eq for Purl
impl StructuralPartialEq for Purl
Auto Trait Implementations§
impl Freeze for Purl
impl RefUnwindSafe for Purl
impl Send for Purl
impl Sync for Purl
impl Unpin for Purl
impl UnwindSafe for Purl
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> 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.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.