pub trait Redactor: Send + Sync {
// Required method
fn redact(&self, input: &str) -> String;
// Provided methods
fn redact_json(&self, value: &mut Value) { ... }
fn redact_value_for_key(&self, _key: &str, value: &mut Value) { ... }
fn redact_key(&self, key: &str) -> String { ... }
}Expand description
Removes user data from report strings.
The default NoopRedactor changes nothing.
BasicRedactor covers the common leaks
(home directory, credential assignments, standalone credentials, emails)
and is the right starting point; a project with its own pattern set
implements this trait over it.
Implementors need only supply Redactor::redact. The JSON hooks have
defaults that walk the structure and route every string through it; a
redactor that can decide from a key — which a per-string scan never sees,
because the key lives in the enclosing object — overrides
Redactor::redact_value_for_key and Redactor::redact_key.
Required Methods§
Provided Methods§
Sourcefn redact_json(&self, value: &mut Value)
fn redact_json(&self, value: &mut Value)
Redact every string node within a JSON value, structure preserved.
Object members are routed through Redactor::redact_key and
Redactor::redact_value_for_key so that a redactor may act on the
key/value relationship, not just on isolated strings.
Beyond MAX_JSON_DEPTH the remaining subtree is replaced with
REDACTED_DEPTH instead of being descended into — see that constant
for why a bound is required rather than merely tidy.
Sourcefn redact_value_for_key(&self, _key: &str, value: &mut Value)
fn redact_value_for_key(&self, _key: &str, value: &mut Value)
Redact one object member, given the key it is stored under.
The default ignores the key and redacts the value on its own merits.
Sourcefn redact_key(&self, key: &str) -> String
fn redact_key(&self, key: &str) -> String
Redact an object key. Keys are usually field names — structure worth keeping — so the default returns them unchanged. A map keyed by user data is the exception, and the reason this hook exists.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".