Anders429 / word_filter

A Word Filter for filtering text.
Apache License 2.0
1 stars 0 forks source link

Support more customization with censoring #12

Closed Anders429 closed 3 years ago

Anders429 commented 3 years ago

Right now, the only option for censoring is to replace every char with a single given char. There is plenty of room for expansion there. Right now, CensorMode is an enum allowing for further fields to allow more methods of customizing.

However, it may work better to define a Censor trait instead, and let users define the censor functionality themselves. A default Censor implementation could be provided as well, for users who still want to censor by replacing characters.

Definition could be something like:

pub trait Censor {
    fn censor(input: &str) -> String;
}

An alternative to a trait could be passing a closure. This could be preferable, since a struct wouldn't likely hold any state anyway.