Skip to main content

counter/
counter.rs

1extern crate streams_rs;
2
3use streams_rs::fn_stream::FnStream;
4use streams_rs::*;
5fn main() {
6    let mut count = 0;
7    let get = || {
8        count += 1;
9        StreamResult::Ok(count - 1)
10    };
11    let mut stream = FnStream::new(get);
12
13    let _ = smatch!(match (stream) {
14        [0=>] => {  // if not 0 then we do not match
15            println!("Zero!");
16        }
17    });
18    let _ = smatch!(match (stream) {
19        [1=>] => { // if not 1 then we do not match
20            println!("One!");
21        }
22    });
23    for _ in 0..10 {
24        let _ = smatch!(match (stream) {
25            [a=>b=>] => { // get two values a and b from stream
26                println!("a: {} b: {}",a,b);
27            }
28        });
29    }
30}