serenade_notifier/
null.rs1use crate::{Channel, Notification, NotifierError, Transport};
4
5#[derive(Clone, Copy, Debug, Default)]
7pub struct NullTransport;
8
9impl NullTransport {
10 #[must_use]
12 pub const fn new() -> Self {
13 Self
14 }
15}
16
17impl Transport for NullTransport {
18 fn supports(&self, channel: Channel) -> bool {
19 matches!(channel, Channel::Sms | Channel::Push)
20 }
21
22 fn send(&self, notification: &Notification) -> Result<(), NotifierError> {
23 validate_for_send(notification)
24 }
25}
26
27pub fn validate_for_send(notification: &Notification) -> Result<(), NotifierError> {
29 match notification {
30 Notification::Sms(message) => {
31 if message.to().trim().is_empty() {
32 return Err(NotifierError::MissingRecipient);
33 }
34 if message.body().trim().is_empty() {
35 return Err(NotifierError::MissingBody);
36 }
37 }
38 Notification::Push(message) => {
39 if message.device_token().trim().is_empty() {
40 return Err(NotifierError::MissingRecipient);
41 }
42 if message.body().trim().is_empty() {
43 return Err(NotifierError::MissingBody);
44 }
45 }
46 }
47 Ok(())
48}