Macro word_filter::_replace_words_with [−][src]
macro_rules! _replace_words_with {
($s : literal) => { ... };
}
Expand description
Creates a sensor replacing the full matched words with the given string.
Example
Assuming a compile-time constructed WordFilter
FILTER
, defined in a build.rs
as:
ⓘ
use std::{
env,
fs::File,
io::{BufWriter, Write},
path::Path,
};
use word_filter_codegen::WordFilterGenerator;
fn main() {
let path = Path::new(&env::var("OUT_DIR").unwrap()).join("codegen.rs");
let mut file = BufWriter::new(File::create(&path).unwrap());
writeln!(
&mut file,
"{}",
WordFilterGenerator::new()
.word("foo")
.generate("FILTER")
);
}
a custom censor function can be used as follows:
ⓘ
include!(concat!(env!("OUT_DIR"), "/codegen.rs"));
assert!(
FILTER.censor_with("this string contains foo", censor::replace_words_with("<censored>")),
"this string contains <censored>"
);