> I don't think `split_whitespace` does any allocations.
Correct. Here's the implementation of split_whitespace
pub fn split_whitespace(&self) -> SplitWhitespace<'_> {
SplitWhitespace { inner: self.split(IsWhitespace).filter(IsNotEmpty) }
}
So, we're just calling split(IsWhitespace).filter(IsNotEmpty) and keeping the resulting iterator.Rust's iterators are lazy, they only do work when asked for the next item, so their internal state is only what is necessary to keep doing that each time.
IsWhitespace and IsNotEmpty are both predicates which do exactly what you think they do, they're provided in the library because they might not get inlined and if they don't we might as well only implement them exactly once.