//! Splitting text into the things tally counts. /// The words of `line`: runs of anything but whitespace. pub fn words(line: &str) -> usize { line.split_whitespace().count() } /// The lines of `text`. A last line without a newline still counts, and /// empty input has none. pub fn lines(text: &str) -> impl Iterator { text.lines().filter(|_| !text.is_empty()) } #[cfg(test)] mod tests { #[test] fn empty_input_has_no_lines() { assert_eq!(super::lines("").count(), 0); } }