Commit 2138ff1d0d8e0e410cbf1d5d0676dfd960019e0c
in the beginning
Michael Williams committed on 5/12/2018, 12:26:59 PMFiles changed
.gitignore | added |
Cargo.lock | added |
Cargo.toml | added |
src/main.rs | added |
Cargo.toml | ||
---|---|---|
@@ -1,0 +1,6 @@ | ||
1 … | +[package] | |
2 … | +name = "metronome" | |
3 … | +version = "0.1.0" | |
4 … | +authors = ["Michael Williams <michael.williams@enspiral.com>"] | |
5 … | + | |
6 … | +[dependencies] |
src/main.rs | ||
---|---|---|
@@ -1,0 +1,28 @@ | ||
1 … | +use std::io; | |
2 … | +use std::io::prelude::*; | |
3 … | + | |
4 … | +use std::thread::sleep; | |
5 … | +use std::time::{Duration}; | |
6 … | + | |
7 … | +fn main () { | |
8 … | + metronome().unwrap(); | |
9 … | +} | |
10 … | + | |
11 … | +fn metronome () -> io::Result<()> { | |
12 … | + let stdin = io::stdin(); | |
13 … | + let mut buffer = vec![0_u8; 2_usize.pow(8)]; | |
14 … | + | |
15 … | + loop { | |
16 … | + let mut handle = stdin.lock(); | |
17 … | + | |
18 … | + match handle.read(&mut buffer) { | |
19 … | + Ok(num_bytes) => { | |
20 … | + println!("{} bytes read", num_bytes); | |
21 … | + let string = String::from_utf8(buffer.clone()).unwrap(); | |
22 … | + }, | |
23 … | + Err(error) => println!("error: {}", error), | |
24 … | + } | |
25 … | + | |
26 … | + sleep(Duration::new(0, 30 * 1000)); | |
27 … | + } | |
28 … | +} |
Built with git-ssb-web