pub struct WaterfallRouter { /* private fields */ }Expand description
Waterfall router: tries each provider in order, falls back to the next on failure.
Optimizes cost by trying cheaper channels (email) before expensive ones (SMS). For OTP delivery, automatically detects whether the recipient is an email address or phone number and routes accordingly.
Implementations§
Source§impl WaterfallRouter
impl WaterfallRouter
Sourcepub fn add_sms(self, provider: Arc<dyn SmsSender>) -> Self
pub fn add_sms(self, provider: Arc<dyn SmsSender>) -> Self
Adds an SMS provider to the routing chain. Providers are tried in insertion order.
Sourcepub fn add_email(self, provider: Arc<dyn EmailSender>) -> Self
pub fn add_email(self, provider: Arc<dyn EmailSender>) -> Self
Adds an email provider to the routing chain. Providers are tried in insertion order.
Sourcepub async fn send_otp(
&self,
recipient: &str,
code: &str,
app_name: &str,
) -> Result<SendResult, ChorusError>
pub async fn send_otp( &self, recipient: &str, code: &str, app_name: &str, ) -> Result<SendResult, ChorusError>
Sends an OTP via waterfall routing. Routes to email if recipient contains @, otherwise SMS.
Sourcepub async fn send_sms(
&self,
msg: &SmsMessage,
) -> Result<SendResult, ChorusError>
pub async fn send_sms( &self, msg: &SmsMessage, ) -> Result<SendResult, ChorusError>
Sends an SMS directly, trying each SMS provider in order until one succeeds.
Sourcepub async fn send_email(
&self,
msg: &EmailMessage,
) -> Result<SendResult, ChorusError>
pub async fn send_email( &self, msg: &EmailMessage, ) -> Result<SendResult, ChorusError>
Sends an email directly, trying each email provider in order until one succeeds.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for WaterfallRouter
impl !RefUnwindSafe for WaterfallRouter
impl Send for WaterfallRouter
impl Sync for WaterfallRouter
impl Unpin for WaterfallRouter
impl UnsafeUnpin for WaterfallRouter
impl !UnwindSafe for WaterfallRouter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more