aboutsummaryrefslogtreecommitdiff
path: root/examples/words.rs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/words.rs')
-rw-r--r--examples/words.rs17
1 files changed, 17 insertions, 0 deletions
diff --git a/examples/words.rs b/examples/words.rs
new file mode 100644
index 0000000..eb20c0d
--- /dev/null
+++ b/examples/words.rs
@@ -0,0 +1,17 @@
+extern crate bstr;
+
+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(())
+}