You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
add_word is marked deprecated and i have no how to add custom word with Trie, or Cencor::with_trie like it suggests. Small simple example would be great.
The text was updated successfully, but these errors were encountered:
Im trying to initialize empty trie with only few custom words:
fn main() {
let mut trie = Trie::new();
trie.set("bad word", Type::OFFENSIVE);
let t = Censor::from_str("contains bad word").with_trie(&trie).analyze();
assert_eq!(t, Type::OFFENSIVE);
}
I get:
trie does not live long enough
borrowed value does not live long enough
let trie = unsafe { Trie::customize_default() };
trie.clone_from(&Trie::new());
trie.set("bad word", Type::OFFENSIVE);
let t = Censor::from_str("contains offensive bad word").with_trie(trie).analyze();
assert_eq!(t, Type::OFFENSIVE);
Due to the current &'static lifetime requirement of Censor::with_trie, it's necessary to do a hack like what you found orBox::leak(Box::new(Trie::new())), which doesn't use unsafe.
In the future, I hope to improve the API and/or the documentation.
Motivation
add_word is marked deprecated and i have no how to add custom word with Trie, or Cencor::with_trie like it suggests. Small simple example would be great.
The text was updated successfully, but these errors were encountered: