#word #filter #string #wordfilter #censor

no-std word_filter_codegen

Utilities for generating WordFilters at compile-time

4 releases (2 breaking)

0.7.0 Aug 1, 2021
0.6.0 Jun 23, 2021
0.5.1 May 28, 2021
0.5.0 May 28, 2021

#23 in #word

Download history 12/week @ 2022-03-13 12/week @ 2022-03-20 16/week @ 2022-04-24 21/week @ 2022-05-01 32/week @ 2022-05-08 68/week @ 2022-05-15 18/week @ 2022-05-22 25/week @ 2022-05-29 20/week @ 2022-06-05 2/week @ 2022-06-12 2/week @ 2022-06-19

53 downloads per month


682 lines


GitHub Workflow Status codecov.io crates.io docs.rs MSRV License

Tools for generating Word Filters.

This crate is intended to be used as a build utility for the word_filter crate. It is used to generate WordFilters at compile-time using a WordFilterGenerator.


For example, a simple WordFilter can be generated by the following.

First, add both the word_filter and word_filter_codegen crates to the Cargo.toml [dependencies] and [build-dependencies] lists respectively. Be sure their versions match.

word_filter = "0.6.0"

word_filter_codegen = "0.6.0"

Next, generate the WordFilter in the build.rs file.

use std::{
    io::{BufWriter, Write},
use word_filter_codegen::{Visibility, WordFilterGenerator};

fn main() {
    let path = Path::new(&env::var("OUT_DIR").unwrap()).join("codegen.rs");
    let mut file = BufWriter::new(File::create(&path).unwrap());

        &mut file,

And finally, include the generated code in the lib.rs file.

include!(concat!(env!("OUT_DIR"), "/codegen.rs"));

assert!(FILTER.censor("Should censor foo."), "Should censor ***.");

Minimum Supported Rust Version

This crate is guaranteed to compile on stable rustc 1.51.0 and up.


This project is licensed under either of

at your option.


Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.


~21K SLoC