[−][src]Function insta::dynamic_redaction
pub fn dynamic_redaction<I, F>(func: F) -> Redaction where
I: Into<Content>,
F: Fn(Content, ContentPath<'_>) -> I + Send + Sync + 'static,
Creates a dynamic redaction.
This can be used to redact a value with a different value but instead of statically declaring it a dynamic value can be computed. This can also be used to perform assertions before replacing the value.
The closure is passed two arguments: the value as Content
and the path that was selected (as ContentPath
).
Example:
settings.add_redaction(".id", dynamic_redaction(|value, path| { assert_eq!(path.to_string(), ".id"); assert_eq!( value .as_str() .unwrap() .chars() .filter(|&c| c == '-') .count(), 4 ); "[uuid]" }));