pub struct Tokenizer { /* private fields */ }Expand description
Streaming tokenizer with reusable scratch buffers.
One instance per engine (or per thread of a wrapper): after warm-up
Tokenizer::tokenize allocates nothing, which the zero-alloc recall
invariant depends on.
Implementations§
Source§impl Tokenizer
impl Tokenizer
Sourcepub fn tokenize(&mut self, text: &str, sink: &mut dyn FnMut(&str))
pub fn tokenize(&mut self, text: &str, sink: &mut dyn FnMut(&str))
Splits text into normalized tokens, calling sink for each one.
The emitted &str is only valid for the duration of one sink
call.
use plugmem_core::tokenizer::Tokenizer;
let mut tk = Tokenizer::new();
let mut tokens = Vec::new();
tk.tokenize("Hello, МИР-42! 東京タワー", &mut |t| tokens.push(t.to_owned()));
assert_eq!(tokens, ["hello", "мир", "42", "東京", "タワー"]);Trait Implementations§
Auto Trait Implementations§
impl Freeze for Tokenizer
impl RefUnwindSafe for Tokenizer
impl Send for Tokenizer
impl Sync for Tokenizer
impl Unpin for Tokenizer
impl UnsafeUnpin for Tokenizer
impl UnwindSafe for Tokenizer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more