this/events/types.rs
1//! Core types for the event log system
2
3use serde::{Deserialize, Serialize};
4
5/// Sequence number in the event log (monotonically increasing)
6pub type SeqNo = u64;
7
8/// Seek position for event log consumers
9///
10/// Determines where a consumer starts reading from when subscribing.
11#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
12pub enum SeekPosition {
13 /// Start from the very beginning — replay all events
14 Beginning,
15 /// Resume from the last acknowledged position for this consumer
16 LastAcknowledged,
17 /// Start from now — only receive future events
18 #[default]
19 Latest,
20 /// Start from a specific sequence number
21 Sequence(SeqNo),
22}
23
24impl From<crate::config::SeekMode> for SeekPosition {
25 fn from(mode: crate::config::SeekMode) -> Self {
26 match mode {
27 crate::config::SeekMode::Beginning => SeekPosition::Beginning,
28 crate::config::SeekMode::LastAcknowledged => SeekPosition::LastAcknowledged,
29 crate::config::SeekMode::Latest => SeekPosition::Latest,
30 }
31 }
32}
33
34/// State of a consumer group
35#[derive(Debug, Clone)]
36pub struct ConsumerState {
37 /// Consumer group name
38 pub name: String,
39 /// Last acknowledged sequence number (None if never acked)
40 pub last_acked: Option<SeqNo>,
41}