mod.rs

Overview

This file defines the MessagesRange struct, which manages a sequence of messages identified by keys. It provides a data structure combining a potentially compacted history range with a tail queue of message-key pairs, allowing efficient appending and tracking of message sequences. The file includes core functionality to create an empty message range, check if it is empty, add new messages, and retrieve its current length. It also implements traits for serialization, deserialization, getters, setters, cloning, and a debug formatter.

The file exposes a submodule named next, which is not detailed here but is part of the message range handling.

Struct: MessagesRange<MessageKey, Message>

Purpose

MessagesRange represents a collection of messages ordered by their keys with two main components:

This structure supports scenarios where older messages might be summarized or compacted, while newer messages remain accessible in sequence.

Type Parameters

Derives and Traits

Fields

Methods

empty() -> Self

Creates and returns an empty MessagesRange instance, with no compacted history and an empty tail sequence.

Usage example:

let empty_range: MessagesRange<u32, String> = MessagesRange::empty();
assert!(empty_range.is_empty());

is_empty(&self) -> bool

Checks whether the MessagesRange is empty. Returns true if there is no compacted history and the tail sequence is empty.

Usage example:

if messages_range.is_empty() {
    println!("No messages available.");
}

add_messages(&mut self, messages: Vec<(MessageKey, Message)>)

Appends a vector of (MessageKey, Message) tuples to the tail sequence.

Parameters:

Usage example:

messages_range.add_messages(vec![(1, "msg1".to_string()), (2, "msg2".to_string())]);

length(&self) -> usize

Returns the number of messages currently in the tail sequence.

Usage example:

let count = messages_range.length();
println!("Number of messages in tail: {}", count);

Debug Implementation

A manual implementation of Debug is provided to display the compacted_history and tail_sequence contents in debug logs. This aids in inspection during development or testing.

Implementation Details

Interaction with Other Parts of the Application

Diagram: MessagesRange Structure and Methods

classDiagram
class MessagesRange {
+Option<RangeInclusive<MessageKey>> compacted_history
+VecDeque<(MessageKey, Message)> tail_sequence
+empty()
+is_empty()
+add_messages()
+length()
}