serenade_notifier/
memory.rs1use std::sync::Mutex;
4
5use crate::null::validate_for_send;
6use crate::{Channel, Notification, NotifierError, Transport};
7
8#[derive(Debug, Default)]
10pub struct MemoryTransport {
11 sent: Mutex<Vec<Notification>>,
12}
13
14impl MemoryTransport {
15 #[must_use]
17 pub fn new() -> Self {
18 Self::default()
19 }
20
21 #[must_use]
27 pub fn sent(&self) -> Vec<Notification> {
28 self.sent.lock().expect("memory transport lock").clone()
29 }
30
31 pub fn clear(&self) {
37 self.sent.lock().expect("memory transport lock").clear();
38 }
39}
40
41impl Transport for MemoryTransport {
42 fn supports(&self, channel: Channel) -> bool {
43 matches!(channel, Channel::Sms | Channel::Push)
44 }
45
46 fn send(&self, notification: &Notification) -> Result<(), NotifierError> {
47 validate_for_send(notification)?;
48 self.sent
49 .lock()
50 .expect("memory transport lock")
51 .push(notification.clone());
52 Ok(())
53 }
54}