Skip to main content

zeph_memory/
types.rs

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