Rust
use defingerprinter::engine::Redactor;
use std::env;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let model = env::var("DEFINGERPRINTER_MODEL_DIR")?;
let runtime = env::var("DEFINGERPRINTER_RUNTIME")?;
let mut redactor = Redactor::new(model.into(), runtime.into());
let text = redactor.redact("en", "Contact alice@example.com")?;
println!("{text}");
Ok(())
}
Output: Contact [EMAIL_1]. Reuse the redactor for further calls; its session is released when dropped.
See the Rust API reference and Redactor methods.
Setup
Add the checkout to your application’s Cargo.toml:
[dependencies]
defingerprinter = { path = "/path/to/defingerprinter" }
The example reads the model directory and ONNX Runtime library path from the environment. From this checkout, Nix supplies both:
nix develop -c cargo run --locked --example rust