Debian Codegraph @

src/tests/iter.rs

raw symbols SCIP
1 use craterust-analyzer cargo ringbuf 0.3.3 crate/::HeapRbrust-analyzer cargo ringbuf 0.3.3 alias/HeapRb#;
2
3 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
4 fn iterrust-analyzer cargo ringbuf 0.3.3 tests/iter/iter().() {
5 let buf = HeapRbrust-analyzer cargo ringbuf 0.3.3 alias/HeapRb#::<i32>::newrust-analyzer cargo ringbuf 0.3.3 ring_buffer/init/impl#[`SharedRb<T, Vec<MaybeUninit<T>>>`]new().(2);
6 let (mut prod, mut cons) = buf.splitrust-analyzer cargo ringbuf 0.3.3 ring_buffer/shared/impl#[`SharedRb<T, C>`]split().();
7
8 prod.pushrust-analyzer cargo ringbuf 0.3.3 producer/impl#[`Producer<T, R>`]push().(10).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
9 prod.pushrust-analyzer cargo ringbuf 0.3.3 producer/impl#[`Producer<T, R>`]push().(20).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
10
11 let sum: i32 = cons.iterrust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, R>`]iter().().sumrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#sum().();
12
13 let first = cons.poprust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, R>`]pop().().expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("First item is not available");
14 let second = cons.poprust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, R>`]pop().().expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("Second item is not available");
15
16 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(sum, first +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Add<Self>`]add(). second);
17 }
18
19 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
20 fn iter_mutrust-analyzer cargo ringbuf 0.3.3 tests/iter/iter_mut().() {
21 let buf = HeapRbrust-analyzer cargo ringbuf 0.3.3 alias/HeapRb#::<i32>::newrust-analyzer cargo ringbuf 0.3.3 ring_buffer/init/impl#[`SharedRb<T, Vec<MaybeUninit<T>>>`]new().(2);
22 let (mut prod, mut cons) = buf.splitrust-analyzer cargo ringbuf 0.3.3 ring_buffer/shared/impl#[`SharedRb<T, C>`]split().();
23
24 prod.pushrust-analyzer cargo ringbuf 0.3.3 producer/impl#[`Producer<T, R>`]push().(10).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
25 prod.pushrust-analyzer cargo ringbuf 0.3.3 producer/impl#[`Producer<T, R>`]push().(20).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
26
27 for v in cons.iter_mutrust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, R>`]iter_mut().() {
28 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().v rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`MulAssign<Self>`]mul_assign().*=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`MulAssign<Self>`]mul_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`MulAssign<Self>`]mul_assign().2;
29 }
30
31 let sum: i32 = cons.iterrust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, R>`]iter().().sumrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#sum().();
32
33 let first = cons.poprust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, R>`]pop().().expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("First item is not available");
34 let second = cons.poprust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, R>`]pop().().expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("Second item is not available");
35
36 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(sum, first +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Add<Self>`]add(). second);
37 }
38
39 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
40 fn pop_iterrust-analyzer cargo ringbuf 0.3.3 tests/iter/pop_iter().() {
41 let buf = HeapRbrust-analyzer cargo ringbuf 0.3.3 alias/HeapRb#::<i32>::newrust-analyzer cargo ringbuf 0.3.3 ring_buffer/init/impl#[`SharedRb<T, Vec<MaybeUninit<T>>>`]new().(3);
42 let (mut prod, mut cons) = buf.splitrust-analyzer cargo ringbuf 0.3.3 ring_buffer/shared/impl#[`SharedRb<T, C>`]split().();
43
44 prod.pushrust-analyzer cargo ringbuf 0.3.3 producer/impl#[`Producer<T, R>`]push().(0).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
45 prod.pushrust-analyzer cargo ringbuf 0.3.3 producer/impl#[`Producer<T, R>`]push().(1).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
46 for (i, v) in cons.pop_iterrust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, R>`]pop_iter().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() {
47 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(i as i32, v);
48 }
49
50 prod.pushrust-analyzer cargo ringbuf 0.3.3 producer/impl#[`Producer<T, R>`]push().(2).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
51 prod.pushrust-analyzer cargo ringbuf 0.3.3 producer/impl#[`Producer<T, R>`]push().(3).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
52 for (i, v) in cons.pop_iterrust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, R>`]pop_iter().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() {
53 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(i as i32 +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Add<Self>`]add(). 2, v);
54 }
55 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(prod.is_emptyrust-analyzer cargo ringbuf 0.3.3 producer/impl#[`Producer<T, R>`]is_empty().());
56 }
57
58 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
59 fn push_pop_iter_partialrust-analyzer cargo ringbuf 0.3.3 tests/iter/push_pop_iter_partial().() {
60 let buf = HeapRbrust-analyzer cargo ringbuf 0.3.3 alias/HeapRb#::<i32>::newrust-analyzer cargo ringbuf 0.3.3 ring_buffer/init/impl#[`SharedRb<T, Vec<MaybeUninit<T>>>`]new().(4);
61 let (mut prod, mut cons) = buf.splitrust-analyzer cargo ringbuf 0.3.3 ring_buffer/shared/impl#[`SharedRb<T, C>`]split().();
62
63 prod.pushrust-analyzer cargo ringbuf 0.3.3 producer/impl#[`Producer<T, R>`]push().(0).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
64 prod.pushrust-analyzer cargo ringbuf 0.3.3 producer/impl#[`Producer<T, R>`]push().(1).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
65 prod.pushrust-analyzer cargo ringbuf 0.3.3 producer/impl#[`Producer<T, R>`]push().(2).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
66 for (i, v) in (0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#2).ziprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#zip().(cons.pop_iterrust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, R>`]pop_iter().()) {
67 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(i, v);
68 }
69
70 prod.pushrust-analyzer cargo ringbuf 0.3.3 producer/impl#[`Producer<T, R>`]push().(3).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
71 prod.pushrust-analyzer cargo ringbuf 0.3.3 producer/impl#[`Producer<T, R>`]push().(4).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
72 prod.pushrust-analyzer cargo ringbuf 0.3.3 producer/impl#[`Producer<T, R>`]push().(5).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
73 for (i, v) in (2..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#5).ziprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#zip().(cons.pop_iterrust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, R>`]pop_iter().()) {
74 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(i, v);
75 }
76 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(cons.poprust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, R>`]pop().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), 5);
77 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(prod.is_emptyrust-analyzer cargo ringbuf 0.3.3 producer/impl#[`Producer<T, R>`]is_empty().());
78 }