timely_communication/allocator/canary.rs
1//! A helper struct to report when something has been dropped.
2
3use std::rc::Rc;
4use std::cell::RefCell;
5
6/// An opaque type that reports when it is dropped.
7pub struct Canary {
8 index: usize,
9 queue: Rc<RefCell<Vec<usize>>>,
10}
11
12impl Canary {
13 /// Allocates a new drop canary.
14 pub fn new(index: usize, queue: Rc<RefCell<Vec<usize>>>) -> Self {
15 Canary { index, queue }
16 }
17}
18
19impl Drop for Canary {
20 fn drop(&mut self) {
21 self.queue.borrow_mut().push(self.index);
22 }
23}