pub struct FallbackClient { /* private fields */ }Expand description
An SmsClient that tries a list of providers in order, returning the
first successful response.
This is the pattern every consumer re-invents for primary / backup
failover. FallbackClient encapsulates it once so you don’t have to.
All errors from intermediate providers are collected; if every provider fails, the last error is returned (with a summary of all failures in the message).
§Example
ⓘ
use sms_core::FallbackClient;
let client = FallbackClient::new(vec![
Arc::new(primary_client),
Arc::new(backup_client),
]);
// Tries primary first; on failure, tries backup.
let response = client.send(SendRequest { .. }).await?;Implementations§
Source§impl FallbackClient
impl FallbackClient
Sourcepub fn new(providers: Vec<Arc<dyn SmsClient>>) -> Self
pub fn new(providers: Vec<Arc<dyn SmsClient>>) -> Self
Create a new fallback chain.
Providers are tried in the order given. The list must contain at least one provider.
Sourcepub fn from_clients(clients: Vec<Box<dyn SmsClient>>) -> Self
pub fn from_clients(clients: Vec<Box<dyn SmsClient>>) -> Self
Convenience builder that wraps each client in an Arc for you.
Trait Implementations§
Source§impl SmsClient for FallbackClient
impl SmsClient for FallbackClient
Source§fn send<'life0, 'life1, 'async_trait>(
&'life0 self,
req: SendRequest<'life1>,
) -> Pin<Box<dyn Future<Output = Result<SendResponse, SmsError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn send<'life0, 'life1, 'async_trait>(
&'life0 self,
req: SendRequest<'life1>,
) -> Pin<Box<dyn Future<Output = Result<SendResponse, SmsError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Try each provider in order. Returns the first success or, if all fail, an error summarizing every failure.
Auto Trait Implementations§
impl Freeze for FallbackClient
impl !RefUnwindSafe for FallbackClient
impl Send for FallbackClient
impl Sync for FallbackClient
impl Unpin for FallbackClient
impl UnsafeUnpin for FallbackClient
impl !UnwindSafe for FallbackClient
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