summaryrefslogtreecommitdiffstats
path: root/third_party/rust/ringbuf/examples/simple.rs
blob: 7ee372d4d1b68baf11343dc59d77d5e28e7370ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
extern crate ringbuf;

use ringbuf::RingBuffer;

fn main() {
    let rb = RingBuffer::<i32>::new(2);
    let (mut prod, mut cons) = rb.split();

    prod.push(0).unwrap();
    prod.push(1).unwrap();
    assert_eq!(prod.push(2), Err(2));

    assert_eq!(cons.pop().unwrap(), 0);

    prod.push(2).unwrap();

    assert_eq!(cons.pop().unwrap(), 1);
    assert_eq!(cons.pop().unwrap(), 2);
    assert_eq!(cons.pop(), None);
}