Skip to main content

PackageName

Struct PackageName 

Source
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

Source

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");
Source

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");
Source

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");
Source

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

Source§

fn as_ref(&self) -> &str

Converts this type into a shared reference of the (usually inferred) input type.
Source§

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§

fn borrow(&self) -> &str

Immutably borrows from an owned value. Read more
Source§

impl Clone for PackageName

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PackageName

Source§

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).

Source§

impl Eq for PackageName

Source§

impl From<&str> for PackageName

Source§

fn from(value: &str) -> Self

Converts to this type from the input type.
Source§

impl From<String> for PackageName

Source§

fn from(value: String) -> Self

Converts to this type from the input type.
Source§

impl Hash for PackageName

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for PackageName

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialEq<&str> for PackageName

Source§

fn eq(&self, other: &&str) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialEq<str> for PackageName

Source§

fn eq(&self, other: &str) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for PackageName

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more