diff options
Diffstat (limited to 'vendor/bstr/examples/words.rs')
-rw-r--r-- | vendor/bstr/examples/words.rs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/vendor/bstr/examples/words.rs b/vendor/bstr/examples/words.rs new file mode 100644 index 000000000..db305da0d --- /dev/null +++ b/vendor/bstr/examples/words.rs @@ -0,0 +1,15 @@ +use std::error::Error; +use std::io; + +use bstr::{io::BufReadExt, ByteSlice}; + +fn main() -> Result<(), Box<dyn Error>> { + let stdin = io::stdin(); + let mut words = 0; + stdin.lock().for_byte_line_with_terminator(|line| { + words += line.words().count(); + Ok(true) + })?; + println!("{}", words); + Ok(()) +} |