Loading RustViz Engine...
Implement custom Iterator yielding &str slices of whitespace-separated tokens.
This problem is currently in blueprint template mode. Once the concept foundation is finalized, live in-browser WebAssembly compilation and test assertion runners will be enabled here.
pub struct WordSplitter<'a> {
remainder: &'a str,
}
impl<'a> Iterator for WordSplitter<'a> {
type Item = &'a str;
fn next(&mut self) -> Option<Self::Item> {
self.remainder = self.remainder.trim_start();
if self.remainder.is_empty() { return None; }
let end = self.remainder.find(char::is_whitespace).unwrap_or(self.remainder.len());
let word = &self.remainder[..end];
self.remainder = &self.remainder[end..];
Some(word)
}
}