Skip to main content

serenade_notifier/
sms_only.rs

1//! Transport that only accepts SMS.
2
3use crate::null::validate_for_send;
4use crate::{Channel, Notification, NotifierError, Transport};
5
6/// Rejects push; accepts SMS (useful when only an SMS vendor is wired).
7#[derive(Clone, Copy, Debug, Default)]
8pub struct SmsOnlyTransport;
9
10impl SmsOnlyTransport {
11    /// Creates an SMS-only transport.
12    #[must_use]
13    pub const fn new() -> Self {
14        Self
15    }
16}
17
18impl Transport for SmsOnlyTransport {
19    fn supports(&self, channel: Channel) -> bool {
20        matches!(channel, Channel::Sms)
21    }
22
23    fn send(&self, notification: &Notification) -> Result<(), NotifierError> {
24        if !self.supports(notification.channel()) {
25            return Err(NotifierError::UnsupportedChannel {
26                channel: notification.channel().as_str().to_owned(),
27            });
28        }
29        validate_for_send(notification)
30    }
31}