Module word_filter::censor [−][src]
Expand description
Macros for creating censors to be used in a WordFilter
.
These macros are provided for conveniently creating common censor functions. The resulting
functions have the signature fn(&str) -> String
and can therefore be provided when calling
the censor_with()
method on a WordFilter
.
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") ); }
an input can be censored with a custom censor function as follows:
ⓘ
use word_filter::censor; include!(concat!(env!("OUT_DIR"), "/codegen.rs")); assert!( FILTER.censor_with("this string contains foo", censor::replace_graphemes_with("#")), "this string contains ###" );
Macros
Creates a censor replacing every grapheme with the given string.
Creates a sensor replacing the full matched words with the given string.