Module word_filter::censor [−][src]
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 during building
of a WordFilter
.
Examples
Creating a WordFilter
with a custom censor is done as follows:
use word_filter::{censor, WordFilterBuilder}; let filter = WordFilterBuilder::new().censor(censor::replace_graphemes_with!("#")).build();
Note that if the options here do not suite your use case, you can provide a custom function with a closure instead. The following code block has the same effect as the one above:
use word_filter::WordFilterBuilder; let filter = WordFilterBuilder::new() .censor(|input| input.chars().fold(String::with_capacity(input.len()), |mut acc, _| { acc.push('#'); acc })) .build();
This is a bit more verbose, which is why these macros are provided for the most common cases.
Macros
replace_graphemes_with | Creates a censor replacing every grapheme with the given string. |
replace_words_with | Creates a sensor replacing the full matched words with the given string. |