Struct Redactions
pub struct Redactions {
vars: Option<BTreeMap<RedactedValueInner, BTreeSet<&'static str>>>,
unused: Option<BTreeSet<RedactedValueInner>>,
}Expand description
Replace data with placeholders
This can be used for:
- Handling test-run dependent data like temp directories or elapsed time
- Making special characters more obvious (e.g. redacting a tab a
[TAB]) - Normalizing platform-specific data like
std::env::consts::EXE_SUFFIX
§Examples
let mut subst = snapbox::Redactions::new();
subst.insert("[LOCATION]", "World");
assert_eq!(subst.redact("Hello World!"), "Hello [LOCATION]!");Fields§
§vars: Option<BTreeMap<RedactedValueInner, BTreeSet<&'static str>>>§unused: Option<BTreeSet<RedactedValueInner>>Implementations§
§impl Redactions
impl Redactions
pub const fn new() -> Redactions
pub fn insert(
&mut self,
placeholder: &'static str,
value: impl Into<RedactedValue>,
) -> Result<(), Error>
pub fn insert( &mut self, placeholder: &'static str, value: impl Into<RedactedValue>, ) -> Result<(), Error>
Insert an additional match pattern
placeholder must be enclosed in [ and ].
let mut subst = snapbox::Redactions::new();
subst.insert("[EXE]", std::env::consts::EXE_SUFFIX);With the regex feature, you can define patterns using regexes.
You can choose to replace a subset of the regex by giving it the named capture group
redacted.
let mut subst = snapbox::Redactions::new();
subst.insert("[OBJECT]", regex::Regex::new("(?<redacted>(world|moon))").unwrap());
assert_eq!(subst.redact("Hello world!"), "Hello [OBJECT]!");
assert_eq!(subst.redact("Hello moon!"), "Hello [OBJECT]!");
assert_eq!(subst.redact("Hello other!"), "Hello other!");pub fn extend(
&mut self,
vars: impl IntoIterator<Item = (&'static str, impl Into<RedactedValue>)>,
) -> Result<(), Error>
pub fn extend( &mut self, vars: impl IntoIterator<Item = (&'static str, impl Into<RedactedValue>)>, ) -> Result<(), Error>
Insert additional match patterns
Placeholders must be enclosed in [ and ].
pub fn remove(&mut self, placeholder: &'static str) -> Result<(), Error>
pub fn redact(&self, input: &str) -> String
pub fn redact(&self, input: &str) -> String
Apply redaction only, no pattern-dependent globs
§Examples
let mut subst = snapbox::Redactions::new();
subst.insert("[LOCATION]", "World");
let output = subst.redact("Hello World!");
assert_eq!(output, "Hello [LOCATION]!");pub fn clear_unused<'v>(&self, pattern: &'v str) -> Cow<'v, str>
pub fn clear_unused<'v>(&self, pattern: &'v str) -> Cow<'v, str>
Clear unused redactions from expected data
Some redactions can be conditionally present, like redacting std::env::consts::EXE_SUFFIX.
When the redaction is not present, it needs to be removed from the expected data so it can
be matched against the actual data.
Trait Implementations§
§impl Clone for Redactions
impl Clone for Redactions
§fn clone(&self) -> Redactions
fn clone(&self) -> Redactions
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more§impl Debug for Redactions
impl Debug for Redactions
§impl Default for Redactions
impl Default for Redactions
§fn default() -> Redactions
fn default() -> Redactions
§impl PartialEq for Redactions
impl PartialEq for Redactions
impl Eq for Redactions
impl StructuralPartialEq for Redactions
Auto Trait Implementations§
impl Freeze for Redactions
impl RefUnwindSafe for Redactions
impl Send for Redactions
impl Sync for Redactions
impl Unpin for Redactions
impl UnsafeUnpin for Redactions
impl UnwindSafe for Redactions
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,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,
§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 64 bytes