PII masking for Rust applications.

mask-pii helps you mask sensitive strings such as email addresses and phone numbers before logging, exporting, or sharing data.

Email masking

Masks local parts while preserving domains: alice@example.com -> a****@example.com.

Phone masking

Masks middle digits while preserving formatting: +1 (800) 123-4567 -> +1 (***) ***-4567.

Flexible config

Enable only the rules you need and customize the mask character and behavior.

Install and Use

Add the crate with cargo add mask-pii (or mask-pii = "0.1.0" in Cargo.toml), then configure a masker and process input text.

Install

cargo add mask-pii

Usage

main.rs
use mask_pii::Masker;

fn main() {
  // Configure masking rules
  let masker = Masker::new()
    .mask_emails()
    .mask_phones()
    .with_mask_char('#');

  let input = "Contact: alice@example.com or 090-1234-5678.";
  let output = masker.process(input);

  println!("{}", output);
  // Output: "Contact: a####@example.com or 090-####-5678."
}
One More Tip

Start from Masker::new() and enable only the masking rules required by your system. You can combine email and phone masking in a single pipeline.