arminius_lib_room_service_messages/lib.rs
1// SPDX-FileCopyrightText: 2025 BWI GmbH
2//
3// SPDX-License-Identifier: Apache-2.0
4
5//! The bus API of the room service: the facts it publishes about rooms.
6#![doc = include_str!("../README.md")]
7
8mod event;
9#[cfg(test)]
10mod tests;
11
12pub use event::{EventProvenance, ReadReceiptAdded, RoomEventAdded};
13
14/// How a consumer recognises two publications as describing the same thing.
15///
16/// A consumer that batches work may still be holding a message when the broker
17/// redelivers it, and has to collapse the two. The key is opaque and only ever
18/// compared for equality.
19#[derive(Debug, Clone, PartialEq, Eq, Hash)]
20pub struct DedupKey(String);
21
22impl std::fmt::Display for DedupKey {
23 fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
24 formatter.write_str(&self.0)
25 }
26}
27
28/// Separator between the parts of a composite [`DedupKey`].
29///
30/// ASCII unit separator: it exists for exactly this, and cannot occur in a
31/// Matrix identifier, so no two distinct receipts can join to the same string.
32const KEY_SEPARATOR: char = '\u{1f}';
33
34/// A fact whose identity survives redelivery.
35pub trait Deduplicate {
36 /// A value equal for two publications describing the same thing, and
37 /// different otherwise.
38 fn dedup_key(&self) -> DedupKey;
39}