debian/rust-vendor/bstr/examples/words.rs
raw| 1 | use std::error::Error; |
| 2 | use std::io; |
| 3 | |
| 4 | use bstr::{io::BufReadExt, ByteSlice}; |
| 5 | |
| 6 | fn main() -> Result<(), Box<dyn Error>> { |
| 7 | let stdin = io::stdin(); |
| 8 | let mut words = 0; |
| 9 | stdin.lock().for_byte_line_with_terminator(|line| { |
| 10 | words += line.words().count(); |
| 11 | Ok(true) |
| 12 | })?; |
| 13 | println!("{}", words); |
| 14 | Ok(()) |
| 15 | } |