@DOUBT: The caller will need to remember to call close_cursor, other wise the cursors will keep accumulating. One way to prevent that can be to implement Drop trait for the Cursor struct. But for that, we'd need to have the cursors hashmap inside an Arc so that a reference to it can be shared with the Cursor struct. Then in the Cursor::drop method, the cursor can be removed from the hashmap.
(&self, cursor_id: u64)
| 181 | // Cursor struct. Then in the Cursor::drop method, the cursor can |
| 182 | // be removed from the hashmap. |
| 183 | pub fn close_cursor(&self, cursor_id: u64) -> Result<(), BufIoError> { |
| 184 | let mut cursors = self.cursors.write().map_err(|_| BufIoError::Locking)?; |
| 185 | cursors.remove(&cursor_id); |
| 186 | Ok(()) |
| 187 | } |
| 188 | |
| 189 | fn get_or_create_region(&self, position: u64) -> Result<Arc<BufferRegion>, BufIoError> { |
| 190 | let start = position - (position % self.buffer_size as u64); |