Skip to main content

SmsClient

Trait SmsClient 

Source
pub trait SmsClient: Send + Sync {
    // Required method
    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;
}
Expand description

The primary trait for sending SMS messages.

Every provider crate (sms-plivo, sms-aws-sns, sms-twilio) implements this trait. Because the trait is object-safe (Send + Sync, no associated types), you can use Box<dyn SmsClient> or Arc<dyn SmsClient> for dynamic dispatch — which is exactly what SmsRouter and FallbackClient do under the hood.

§Example

use sms_core::{SmsClient, SendRequest};

async fn send_otp(client: &dyn SmsClient) -> Result<String, sms_core::SmsError> {
    let resp = client.send(SendRequest {
        to: "+14155551234",
        from: "+10005551234",
        text: "Your code is 123456",
    }).await?;
    Ok(resp.id)
}

Required Methods§

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,

Send a single text SMS and return the provider’s response.

Implementors§