We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e44451a commit fdf0e3aCopy full SHA for fdf0e3a
examples/line-count.rs
@@ -0,0 +1,29 @@
1
+//! Counts the number of lines in a file given as an argument.
2
+
3
+#![feature(async_await)]
4
5
+use std::env::args;
6
7
+use async_std::fs::File;
8
+use async_std::io::{self, BufReader};
9
+use async_std::prelude::*;
10
+use async_std::task;
11
12
+fn main() -> io::Result<()> {
13
+ let path = args().nth(1).expect("missing path argument");
14
15
+ task::block_on(async {
16
+ let file = BufReader::new(File::open(&path).await?);
17
18
+ let mut lines = file.lines();
19
+ let mut count = 0u64;
20
21
+ while let Some(line) = lines.next().await {
22
+ line?;
23
+ count += 1;
24
+ }
25
26
+ println!("The file contains {} lines.", count);
27
+ Ok(())
28
+ })
29
+}
0 commit comments