pub struct Redactions { /* private fields */ }Expand description
An ordered set of text rewrites applied to a value before it is compared against (or written to) a snapshot.
Build one with the chained methods, then hand it to
check!(value).matches_snapshot_with(name, &redactions) (or the inline
variant). Rules run in the order they were added, each on the output of the
last.
use test_better_core::TestResult;
use test_better_matchers::{eq, check};
use test_better_snapshot::Redactions;
let redactions = Redactions::new().redact_uuids();
let rendered = "user 550e8400-e29b-41d4-a716-446655440000 logged in";
check!(redactions.apply(rendered))
.satisfies(eq("user [uuid] logged in".to_string()))?;Implementations§
Source§impl Redactions
impl Redactions
Sourcepub fn new() -> Redactions
pub fn new() -> Redactions
An empty set: apply returns its input unchanged until a
rule is added.
Sourcepub fn replace(
self,
needle: impl Into<String>,
placeholder: impl Into<String>,
) -> Redactions
pub fn replace( self, needle: impl Into<String>, placeholder: impl Into<String>, ) -> Redactions
Replaces every occurrence of the literal needle with placeholder.
This is the rule for a value you already know, e.g. a generated id you
captured earlier in the test. An empty needle is a no-op rule rather
than a rule that matches everywhere.
Sourcepub fn redact_uuids(self) -> Redactions
pub fn redact_uuids(self) -> Redactions
Replaces every UUID (the canonical 8-4-4-4-12 hex form, either case)
with [uuid].
Sourcepub fn redact_rfc3339_timestamps(self) -> Redactions
pub fn redact_rfc3339_timestamps(self) -> Redactions
Replaces every RFC 3339 / ISO 8601 date-time (e.g.
2026-05-14T12:34:56Z, with optional fractional seconds and either a
Z or a ±hh:mm offset) with [timestamp].
Sourcepub fn redact_with(
self,
rule: impl Fn(&str) -> String + Send + Sync + 'static,
) -> Redactions
pub fn redact_with( self, rule: impl Fn(&str) -> String + Send + Sync + 'static, ) -> Redactions
Adds an arbitrary rewriting rule: the escape hatch for content the built-ins do not cover.
The closure is handed the running text and returns its rewritten form.