iterator.rs

Overview

This file provides an iterator abstraction for traversing a range of messages stored in a durable storage system. It defines an iterator over a MessagesRange, which may include both a compacted history segment stored in the database and a tail sequence cached in memory. The iterator fetches messages on-demand from the storage backend while handling potential storage errors and range inconsistencies. It is generic over the message key type, message type, and the durable storage implementation.

The file also encapsulates error handling related to loading messages or references from storage, and includes internal utilities to manage loading single messages or batches of messages from storage.


Main Components

IteratorError<StorageErr, MessageKey>

An enumeration representing possible errors during iteration:

Type Parameters


MessagesRangeIterator<'a, MessageKey, Message, Storage>

An iterator over a MessagesRange that fetches messages from a durable storage backend and an in-memory tail sequence.

Type Parameters and Constraints

Fields

Methods


Implementation of Iterator trait for MessagesRangeIterator


Internal Module: consume

Contains helper functions to load messages and message ranges from storage, handling iteration logic over storage references.

Functions


Interaction with Other Components


Important Implementation Details


Mermaid Diagram

classDiagram
class MessagesRangeIterator {
-remaining: MessagesRange
-db: &Storage
+new()
+remaining()
+next_range()
+remaining_messages_from_db()
+next()
}
class IteratorError {
<<enum>>
+LoadMessageError
+LoadNextRefError
+BrokenRange
}
class consume {
+from_storage()
+range_from_storage()
}
MessagesRangeIterator ..> MessagesRange : uses
MessagesRangeIterator ..> DurableStorageRead : interacts
MessagesRangeIterator ..> IteratorError : returns
MessagesRangeIterator ..> consume : calls

This diagram shows the core MessagesRangeIterator struct with its methods and relationships to the MessagesRange data structure, the DurableStorageRead trait, the IteratorError enum for error handling, and the internal consume module providing utility functions.