pub struct DataMasker;Implementations§
Source§impl DataMasker
impl DataMasker
Sourcepub fn apply(rule: &MaskingRule, value: &str) -> String
pub fn apply(rule: &MaskingRule, value: &str) -> String
Applies the given masking rule to value. The implementation is
Unicode-safe (works on char boundaries rather than byte slices) and
never panics: inputs shorter than the rule’s required visible prefix
return a sensible fallback (the original value, or "***" when even
the original cannot be safely revealed).
Sourcepub fn apply_many(rules: &[MaskingRule], value: &str) -> String
pub fn apply_many(rules: &[MaskingRule], value: &str) -> String
Applies a sequence of rules to the same value, in order.
Useful for stacked masking (e.g. first mask the whole phone, then apply a custom prefix/suffix rule). Each rule is applied to the output of the previous one.
Sourcepub fn mask_map(
rules: &HashMap<String, MaskingRule>,
data: &HashMap<String, String>,
) -> HashMap<String, String>
pub fn mask_map( rules: &HashMap<String, MaskingRule>, data: &HashMap<String, String>, ) -> HashMap<String, String>
Masks specific fields of a HashMap<String, String> in place,
returning a new map with only the masked fields replaced.
Fields whose rule is None are copied through unchanged. Fields not
present in rules are also copied through, so callers can pass a
partial rule set without losing data.
Sourcepub fn mask_json(rules: &HashMap<String, MaskingRule>, json: &str) -> String
pub fn mask_json(rules: &HashMap<String, MaskingRule>, json: &str) -> String
Masks a JSON object string by field name.
rules maps field names to masking rules. Only top-level fields are
matched (nested objects are left untouched); non-JSON input is
returned unchanged so callers can rely on this being lossless for
malformed payloads.