Hey folks,
I have the following struct:
use std::collections::HashSet;
use tantivy::tokenizer::{SimpleTokenizer, TokenStream, Tokenizer};
pub struct Vocabulary {
#[allow(dead_code)]
tokens: HashSet<String>,
}
impl Default for Vocabulary {
fn default() -> Self {
Self::new()
}
}
impl Vocabulary {
#[allow(dead_code)]
pub fn new() -> Self {
Self { tokens: HashSet::new() }
}
pub fn add_text(& mut self, text: &str) {
let mut tokenizer = SimpleTokenizer::default();
let mut stream = tokenizer.token_stream(text);
stream.process(&mut |token| {
self.tokens.insert(token.text.clone());
});
}
}
I'd like to implement std::iter::Iterator to produce an iterator of Strings from the HashSet. I understand that I need to implement the from() method of the trait, but I'm a little confused as to how to wrap the HashSet's own iterator.
Any help is greatly appreciated.