1use crate::errors::PublisherError;
2use crate::traits::{BatchCommitFunc, CommitFunc};
3use crate::CanonicalMessage;
4
5#[derive(Debug)]
7pub enum Handled {
8 Ack,
11 Publish(CanonicalMessage),
13}
14
15#[derive(Debug)]
17pub enum Sent {
18 Ack,
20 Response(CanonicalMessage),
22}
23
24#[derive(Debug)]
26pub enum SentBatch {
27 Ack,
29 Partial {
31 responses: Option<Vec<CanonicalMessage>>,
32 failed: Vec<(CanonicalMessage, PublisherError)>,
33 },
34}
35
36pub struct Received {
38 pub message: CanonicalMessage,
39 pub commit: CommitFunc,
40}
41
42impl std::fmt::Debug for Received {
43 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
44 f.debug_struct("Received")
45 .field("message", &self.message)
46 .field("commit", &"<CommitFunc>")
47 .finish()
48 }
49}
50
51pub struct ReceivedBatch {
53 pub messages: Vec<CanonicalMessage>,
54 pub commit: BatchCommitFunc,
55}
56
57impl std::fmt::Debug for ReceivedBatch {
58 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
59 f.debug_struct("ReceivedBatch")
60 .field("messages", &self.messages)
61 .field("commit", &"<BatchCommitFunc>")
62 .finish()
63 }
64}
65
66#[cfg(test)]
67mod tests {
68 use super::*;
69 use crate::traits::MessageDisposition;
70
71 #[test]
72 fn test_received_debug_hides_commit_implementation() {
73 let received = Received {
74 message: CanonicalMessage::from("single"),
75 commit: Box::new(|_| Box::pin(async move { Ok(()) })),
76 };
77
78 let debug = format!("{received:?}");
79 assert!(debug.contains("Received"));
80 assert!(debug.contains("<CommitFunc>"));
81 assert!(debug.contains("single"));
82 }
83
84 #[test]
85 fn test_received_batch_debug_hides_commit_implementation() {
86 let batch = ReceivedBatch {
87 messages: vec![
88 CanonicalMessage::from("first"),
89 CanonicalMessage::from("second"),
90 ],
91 commit: Box::new(|dispositions| {
92 Box::pin(async move {
93 assert_eq!(dispositions.len(), 2);
94 assert!(dispositions
95 .into_iter()
96 .all(|disposition| matches!(disposition, MessageDisposition::Ack)));
97 Ok(())
98 })
99 }),
100 };
101
102 let debug = format!("{batch:?}");
103 assert!(debug.contains("ReceivedBatch"));
104 assert!(debug.contains("<BatchCommitFunc>"));
105 assert!(debug.contains("first"));
106 assert!(debug.contains("second"));
107 }
108}