Skip to main content

zeph_memory/
types.rs

1// SPDX-FileCopyrightText: 2026 Andrei G <bug-ops>
2// SPDX-License-Identifier: MIT OR Apache-2.0
3
4/// Strongly typed wrapper for conversation row IDs.
5#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, sqlx::Type)]
6#[sqlx(transparent)]
7pub struct ConversationId(pub i64);
8
9/// Strongly typed wrapper for message row IDs.
10#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, sqlx::Type)]
11#[sqlx(transparent)]
12pub struct MessageId(pub i64);
13
14impl std::fmt::Display for ConversationId {
15    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
16        write!(f, "{}", self.0)
17    }
18}
19
20impl std::fmt::Display for MessageId {
21    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
22        write!(f, "{}", self.0)
23    }
24}
25
26#[cfg(test)]
27mod tests {
28    use super::*;
29
30    #[test]
31    fn conversation_id_display() {
32        let id = ConversationId(42);
33        assert_eq!(format!("{id}"), "42");
34    }
35
36    #[test]
37    fn message_id_display() {
38        let id = MessageId(7);
39        assert_eq!(format!("{id}"), "7");
40    }
41
42    #[test]
43    fn conversation_id_eq() {
44        assert_eq!(ConversationId(1), ConversationId(1));
45        assert_ne!(ConversationId(1), ConversationId(2));
46    }
47
48    #[test]
49    fn message_id_copy() {
50        let id = MessageId(5);
51        let copied = id;
52        assert_eq!(id, copied);
53    }
54}