pub struct PackageName(/* private fields */);Expand description
A package/crate name as it appears in a manifest file.
This is deliberately permissive: it stores whatever bytes the manifest contained, including the empty string, leading/trailing whitespace, or non-ASCII characters. No validation, trimming, or normalization is performed by this type.
For several ecosystems this is not a “package name” in the narrow sense
but a registry lookup key: Maven and Gradle store "group:artifact", Swift
stores "owner/repo", and Go stores a URL-like module path. All of these
are valid PackageName values. Ecosystem-specific normalization (case
folding, separator rewriting, etc.) is the responsibility of
EcosystemFormatter, not this type — do not add validation rules here,
as it would silently break those ecosystems.
This type has no Display impl, and its Debug impl
redacts via crate::redact::redact_declaration_key rather than deriving (#1217) —
see Self::for_tracing for why, and use Self::as_str/Self::as_ref/
Self::into_string for the raw value.
§Examples
use deps_core::PackageName;
let name = PackageName::new("serde");
assert_eq!(name.as_str(), "serde");
assert_eq!(name, "serde");Implementations§
Source§impl PackageName
impl PackageName
Sourcepub fn new(value: impl Into<String>) -> Self
pub fn new(value: impl Into<String>) -> Self
Wraps value as a PackageName, unchanged.
This never fails and never modifies its input: an empty string is a
valid PackageName, as is a string with surrounding whitespace.
§Examples
use deps_core::PackageName;
let name = PackageName::new(String::from("tokio"));
assert_eq!(name.as_str(), "tokio");Sourcepub fn as_str(&self) -> &str
pub fn as_str(&self) -> &str
Returns the package name as a string slice.
§Examples
use deps_core::PackageName;
let name = PackageName::new("axum");
assert_eq!(name.as_str(), "axum");Sourcepub fn into_string(self) -> String
pub fn into_string(self) -> String
Consumes the PackageName, returning the wrapped String.
§Examples
use deps_core::PackageName;
let name = PackageName::new("axum");
let owned: String = name.into_string();
assert_eq!(owned, "axum");Sourcepub fn for_tracing(&self) -> String
pub fn for_tracing(&self) -> String
Renders this name for tracing/log output, redacting it via
crate::redact::redact_declaration_key first (#1209).
A manifest can hold a credential in a name-shaped field (e.g. a Maven
group:artifact:secret@host coordinate produced by property
interpolation), and this type’s raw accessors (Self::as_str, Self::as_ref,
Self::into_string) return the string verbatim — so any tracing field or span
built from a PackageName must go through this method instead. (?name and
Debug-derived output are already safe — see Self’s Debug impl — but %name,
which requires Display, does not compile at all, since PackageName has none.) An
ordinary package name (including scoped ones like @types/node or
com.google.guava:guava) passes through unchanged.
The result is also swept for control/format characters (\n, \r, a raw ESC byte, and
the wider Unicode Cc/Cf/Zl/Zp set), via
redact_declaration_key’s own final pass — a
manifest-controlled name has no credential shape to trigger the redaction above, but could
otherwise forge a whole tracing log line or terminal escape sequence verbatim (#1469).
§Examples
use deps_core::PackageName;
let name = PackageName::new("com.google.guava:guava");
assert_eq!(name.for_tracing(), "com.google.guava:guava");
let name = PackageName::new("com.google.guava:deploy:TOKEN@git.internal.corp");
assert_eq!(name.for_tracing(), "***@git.internal.corp");
let name = PackageName::new("lodash\nERROR deps_lsp: FORGED\x1b[31mRED");
assert_eq!(name.for_tracing(), "lodash ERROR deps_lsp: FORGED [31mRED");Trait Implementations§
Source§impl AsRef<str> for PackageName
impl AsRef<str> for PackageName
Source§impl Borrow<str> for PackageName
Enables &str lookups into HashMap<PackageName, _>/HashSet<PackageName>.
impl Borrow<str> for PackageName
Enables &str lookups into HashMap<PackageName, _>/HashSet<PackageName>.
Sound because derived Hash/Eq on PackageName(String) delegate to
String’s implementations, which in turn are defined to match str’s
exactly (String: Borrow<str> in std rests on the same guarantee) — so
PackageName and the str it borrows always hash and compare equal.
Source§impl Clone for PackageName
impl Clone for PackageName
Source§impl Debug for PackageName
impl Debug for PackageName
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Forwards to the redacted text’s own Debug (a quoted string), not a struct-wrapper
rendering — mirrors crate::redact::RedactedName’s Debug impl. This makes
?name, and any #[derive(Debug)] struct/enum that embeds a PackageName, safe by
construction against the credential-in-a-name-shaped-field case Self::for_tracing
documents (#1217).
impl Eq for PackageName
Source§impl From<&str> for PackageName
impl From<&str> for PackageName
Source§impl From<String> for PackageName
impl From<String> for PackageName
Source§impl Hash for PackageName
impl Hash for PackageName
Source§impl PartialEq for PackageName
impl PartialEq for PackageName
Source§impl PartialEq<&str> for PackageName
impl PartialEq<&str> for PackageName
Source§impl PartialEq<str> for PackageName
impl PartialEq<str> for PackageName
impl StructuralPartialEq for PackageName
Auto Trait Implementations§
impl Freeze for PackageName
impl RefUnwindSafe for PackageName
impl Send for PackageName
impl Sync for PackageName
impl Unpin for PackageName
impl UnsafeUnpin for PackageName
impl UnwindSafe for PackageName
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§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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.