| 1 | use craterust-analyzer cargo ringbuf 0.3.3 crate/::{Consumerrust-analyzer cargo ringbuf 0.3.3 consumer/Consumer#, HeapRbrust-analyzer cargo ringbuf 0.3.3 alias/HeapRb#}; |
| 2 | use allocrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc crate/::collectionsrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/::BTreeSetrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/set/BTreeSet#; |
| 3 | use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::cellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/::RefCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/RefCell#; |
| 4 | |
| 5 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 6 | struct Dropperrust-analyzer cargo ringbuf 0.3.3 tests/drop/Dropper#<'a> { |
| 7 | idrust-analyzer cargo ringbuf 0.3.3 tests/drop/Dropper#id.: i32, |
| 8 | setrust-analyzer cargo ringbuf 0.3.3 tests/drop/Dropper#set.: &'a RefCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/RefCell#<BTreeSetrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/set/BTreeSet#<i32>>, |
| 9 | } |
| 10 | |
| 11 | impl<'a> Dropperrust-analyzer cargo ringbuf 0.3.3 tests/drop/Dropper#<'a> { |
| 12 | fn newrust-analyzer cargo ringbuf 0.3.3 tests/drop/impl#[`Dropper<'a>`]new().(set: &'a RefCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/RefCell#<BTreeSetrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/set/BTreeSet#<i32>>, id: i32) -> Selfrust-analyzer cargo ringbuf 0.3.3 tests/drop/impl#[`Dropper<'a>`] { |
| 13 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().set.borrow_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]borrow_mut().().insertrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/set/impl#[`BTreeSet<T, A>`]insert().(id) { |
| 14 | panicrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/panic!!("value {} already exists", id); |
| 15 | } |
| 16 | Selfrust-analyzer cargo ringbuf 0.3.3 tests/drop/impl#[`Dropper<'a>`] { setrust-analyzer cargo ringbuf 0.3.3 tests/drop/Dropper#set., idrust-analyzer cargo ringbuf 0.3.3 tests/drop/Dropper#id. } |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | impl<'a> Droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/drop/Drop# for Dropperrust-analyzer cargo ringbuf 0.3.3 tests/drop/Dropper#<'a> { |
| 21 | fn droprust-analyzer cargo ringbuf 0.3.3 tests/drop/impl#[`Dropper<'a>`][Drop]drop().(&mut self) { |
| 22 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.setrust-analyzer cargo ringbuf 0.3.3 tests/drop/Dropper#set..borrow_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]borrow_mut().().removerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/set/impl#[`BTreeSet<T, A>`]remove().(&self.idrust-analyzer cargo ringbuf 0.3.3 tests/drop/Dropper#id.) { |
| 23 | panicrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/panic!!("value {} already removed", self.idrust-analyzer cargo ringbuf 0.3.3 tests/drop/Dropper#id.); |
| 24 | } |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 29 | fn singlerust-analyzer cargo ringbuf 0.3.3 tests/drop/single().() { |
| 30 | let set = RefCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/RefCell#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]new().(BTreeSetrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/set/BTreeSet#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/set/impl#[`BTreeSet<T>`]new().()); |
| 31 | |
| 32 | let cap = 3; |
| 33 | let buf = HeapRbrust-analyzer cargo ringbuf 0.3.3 alias/HeapRb#::newrust-analyzer cargo ringbuf 0.3.3 ring_buffer/init/impl#[`SharedRb<T, Vec<MaybeUninit<T>>>`]new().(cap); |
| 34 | |
| 35 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(set.borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]borrow().().lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/set/impl#[`BTreeSet<T, A>`]len().(), 0); |
| 36 | |
| 37 | { |
| 38 | let (mut prod, mut cons) = buf.splitrust-analyzer cargo ringbuf 0.3.3 ring_buffer/shared/impl#[`SharedRb<T, C>`]split().(); |
| 39 | |
| 40 | prod.pushrust-analyzer cargo ringbuf 0.3.3 producer/impl#[`Producer<T, R>`]push().(Dropperrust-analyzer cargo ringbuf 0.3.3 tests/drop/Dropper#::newrust-analyzer cargo ringbuf 0.3.3 tests/drop/impl#[`Dropper<'a>`]new().(&set, 1)).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 41 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(set.borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]borrow().().lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/set/impl#[`BTreeSet<T, A>`]len().(), 1); |
| 42 | prod.pushrust-analyzer cargo ringbuf 0.3.3 producer/impl#[`Producer<T, R>`]push().(Dropperrust-analyzer cargo ringbuf 0.3.3 tests/drop/Dropper#::newrust-analyzer cargo ringbuf 0.3.3 tests/drop/impl#[`Dropper<'a>`]new().(&set, 2)).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 43 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(set.borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]borrow().().lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/set/impl#[`BTreeSet<T, A>`]len().(), 2); |
| 44 | prod.pushrust-analyzer cargo ringbuf 0.3.3 producer/impl#[`Producer<T, R>`]push().(Dropperrust-analyzer cargo ringbuf 0.3.3 tests/drop/Dropper#::newrust-analyzer cargo ringbuf 0.3.3 tests/drop/impl#[`Dropper<'a>`]new().(&set, 3)).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 45 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(set.borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]borrow().().lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/set/impl#[`BTreeSet<T, A>`]len().(), 3); |
| 46 | |
| 47 | 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().(); |
| 48 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(set.borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]borrow().().lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/set/impl#[`BTreeSet<T, A>`]len().(), 2); |
| 49 | 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().(); |
| 50 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(set.borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]borrow().().lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/set/impl#[`BTreeSet<T, A>`]len().(), 1); |
| 51 | |
| 52 | prod.pushrust-analyzer cargo ringbuf 0.3.3 producer/impl#[`Producer<T, R>`]push().(Dropperrust-analyzer cargo ringbuf 0.3.3 tests/drop/Dropper#::newrust-analyzer cargo ringbuf 0.3.3 tests/drop/impl#[`Dropper<'a>`]new().(&set, 4)).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 53 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(set.borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]borrow().().lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/set/impl#[`BTreeSet<T, A>`]len().(), 2); |
| 54 | } |
| 55 | |
| 56 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(set.borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]borrow().().lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/set/impl#[`BTreeSet<T, A>`]len().(), 0); |
| 57 | } |
| 58 | |
| 59 | // TODO: Use transactions. |
| 60 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 61 | fn transactionrust-analyzer cargo ringbuf 0.3.3 tests/drop/transaction().() { |
| 62 | let set = RefCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/RefCell#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]new().(BTreeSetrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/set/BTreeSet#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/set/impl#[`BTreeSet<T>`]new().()); |
| 63 | |
| 64 | let cap = 5; |
| 65 | let buf = HeapRbrust-analyzer cargo ringbuf 0.3.3 alias/HeapRb#::newrust-analyzer cargo ringbuf 0.3.3 ring_buffer/init/impl#[`SharedRb<T, Vec<MaybeUninit<T>>>`]new().(cap); |
| 66 | |
| 67 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(set.borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]borrow().().lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/set/impl#[`BTreeSet<T, A>`]len().(), 0); |
| 68 | { |
| 69 | let (mut prod, mut cons) = buf.splitrust-analyzer cargo ringbuf 0.3.3 ring_buffer/shared/impl#[`SharedRb<T, C>`]split().(); |
| 70 | let mut id = 0; |
| 71 | let mut cnt = 0; |
| 72 | let assert_cnt = |cnt, n, cons: &Consumerrust-analyzer cargo ringbuf 0.3.3 consumer/Consumer#<_, _>, set: &RefCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/RefCell#<BTreeSetrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/set/BTreeSet#<_>>| { |
| 73 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(cnt, n); |
| 74 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(cnt, cons.lenrust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, R>`]len().()); |
| 75 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(cnt, set.borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]borrow().().lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/set/impl#[`BTreeSet<T, A>`]len().()); |
| 76 | }; |
| 77 | |
| 78 | for _ in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#4 { |
| 79 | id rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().1; |
| 80 | cnt rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1; |
| 81 | prod.pushrust-analyzer cargo ringbuf 0.3.3 producer/impl#[`Producer<T, R>`]push().(Dropperrust-analyzer cargo ringbuf 0.3.3 tests/drop/Dropper#::newrust-analyzer cargo ringbuf 0.3.3 tests/drop/impl#[`Dropper<'a>`]new().(&set, id)).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 82 | } |
| 83 | assert_cnt(cnt, 4, &cons, &set); |
| 84 | |
| 85 | for _ in cons.pop_iterrust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, R>`]pop_iter().().takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#take().(2) { |
| 86 | cnt rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().1; |
| 87 | } |
| 88 | assert_cnt(cnt, 2, &cons, &set); |
| 89 | |
| 90 | while !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().prod.is_fullrust-analyzer cargo ringbuf 0.3.3 producer/impl#[`Producer<T, R>`]is_full().() { |
| 91 | id rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().1; |
| 92 | cnt rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1; |
| 93 | prod.pushrust-analyzer cargo ringbuf 0.3.3 producer/impl#[`Producer<T, R>`]push().(Dropperrust-analyzer cargo ringbuf 0.3.3 tests/drop/Dropper#::newrust-analyzer cargo ringbuf 0.3.3 tests/drop/impl#[`Dropper<'a>`]new().(&set, id)).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 94 | } |
| 95 | assert_cnt(cnt, 5, &cons, &set); |
| 96 | |
| 97 | for _ in cons.pop_iterrust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, R>`]pop_iter().() { |
| 98 | cnt rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().1; |
| 99 | } |
| 100 | assert_cnt(cnt, 0, &cons, &set); |
| 101 | |
| 102 | while !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().prod.is_fullrust-analyzer cargo ringbuf 0.3.3 producer/impl#[`Producer<T, R>`]is_full().() { |
| 103 | id rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().1; |
| 104 | cnt rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1; |
| 105 | prod.pushrust-analyzer cargo ringbuf 0.3.3 producer/impl#[`Producer<T, R>`]push().(Dropperrust-analyzer cargo ringbuf 0.3.3 tests/drop/Dropper#::newrust-analyzer cargo ringbuf 0.3.3 tests/drop/impl#[`Dropper<'a>`]new().(&set, id)).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 106 | } |
| 107 | assert_cnt(cnt, 5, &cons, &set); |
| 108 | } |
| 109 | |
| 110 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(set.borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]borrow().().lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/set/impl#[`BTreeSet<T, A>`]len().(), 0); |
| 111 | } |