pub struct RedactedText<K: RedactionKind>(/* private fields */);Expand description
A value that has already been redacted (via K::redact) for safe inclusion in error or
log output — the shared implementation behind RedactedUrl and RedactedName (issue
#1216).
Eagerly redacted at construction: Self::new applies K::redact immediately and
retains only the resulting text, so the raw value passed in is never stored, not even
transiently. The only public read surface — Display,
AsRef<str>, a Debug impl that forwards to the redacted text, and
Self::into_inner (which hands back that same already-redacted text by value) — is
therefore always safe to log: there is no expose()-style escape hatch, because nothing raw
remains to expose.
PartialEq/Eq/Hash compare the redacted text, not the original input — see
RedactedUrl’s own doc for why this is intentional and what it means for using either
alias as a cache key.
Carries no bound on K itself in its own definition — Clone, Debug,
PartialEq, Eq, Hash, and Display are all
hand-written (not derived) so that none of them require K: Clone/K: Hash/etc., and
PhantomData<fn() -> K> (rather than PhantomData<K>) keeps Send/Sync
unconditional regardless of K — mirrors crate::net_policy::ValidatedRegistryUrl<K>’s
identical shape for the identical reason.
§Examples
use deps_core::redact::{RedactedName, RedactedUrl};
let redacted = RedactedUrl::new("https://user:hunter2@registry.example/simple");
assert_eq!(redacted.to_string(), "https://***@registry.example/simple");
let redacted = RedactedName::new("com.google.guava:guava");
assert_eq!(redacted.to_string(), "com.google.guava:guava");Implementations§
Source§impl<K: RedactionKind> RedactedText<K>
impl<K: RedactionKind> RedactedText<K>
Sourcepub fn new(raw: &str) -> Self
pub fn new(raw: &str) -> Self
Redacts raw immediately via K::redact, retaining only the resulting text.
Sourcepub fn into_inner(self) -> String
pub fn into_inner(self) -> String
Takes ownership of the redacted text without allocating a second copy — unlike
Display/AsRef<str>, which only ever hand back a borrow and so
require the caller to clone if it needs an owned String.
Trait Implementations§
Source§impl<K: RedactionKind> AsRef<str> for RedactedText<K>
impl<K: RedactionKind> AsRef<str> for RedactedText<K>
Source§impl<K: RedactionKind> Clone for RedactedText<K>
impl<K: RedactionKind> Clone for RedactedText<K>
Source§impl<K: RedactionKind> Debug for RedactedText<K>
impl<K: RedactionKind> Debug for RedactedText<K>
Source§impl<K: RedactionKind> Display for RedactedText<K>
impl<K: RedactionKind> Display for RedactedText<K>
impl<K: RedactionKind> Eq for RedactedText<K>
Source§impl<K: RedactionKind> From<&str> for RedactedText<K>
impl<K: RedactionKind> From<&str> for RedactedText<K>
Source§impl<K: RedactionKind> From<String> for RedactedText<K>
impl<K: RedactionKind> From<String> for RedactedText<K>
Source§impl<K: RedactionKind> Hash for RedactedText<K>
impl<K: RedactionKind> Hash for RedactedText<K>
Source§impl<K: RedactionKind> PartialEq for RedactedText<K>
impl<K: RedactionKind> PartialEq for RedactedText<K>
Source§impl<K: RedactionKind> PartialEq<&str> for RedactedText<K>
impl<K: RedactionKind> PartialEq<&str> for RedactedText<K>
Source§impl<K: RedactionKind> PartialEq<str> for RedactedText<K>
impl<K: RedactionKind> PartialEq<str> for RedactedText<K>
Auto Trait Implementations§
impl<K> Freeze for RedactedText<K>
impl<K> RefUnwindSafe for RedactedText<K>
impl<K> Send for RedactedText<K>
impl<K> Sync for RedactedText<K>
impl<K> Unpin for RedactedText<K>
impl<K> UnsafeUnpin for RedactedText<K>
impl<K> UnwindSafe for RedactedText<K>
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.