lettermint_laravel/lib.rs
1//! The official [Lettermint](https://lettermint.co) driver for
2//! [Laravel for Rust](https://docs.rs/laravel-rust): send email through Lettermint, use the
3//! Lettermint API, and receive verified webhook events.
4//!
5//! The driver builds on the official [Lettermint Rust SDK](https://docs.rs/lettermint). Its
6//! requests go through Laravel's HTTP client, so `laravel::http::client::fake()` fakes them in
7//! tests.
8//!
9//! Add the [service provider](LettermintServiceProvider):
10//!
11//! ```no_run
12//! use std::process::ExitCode;
13//!
14//! use laravel::Application;
15//! use lettermint_laravel::LettermintServiceProvider;
16//!
17//! fn main() -> ExitCode {
18//! Application::configure()
19//! .with_providers(|providers| {
20//! providers.add(LettermintServiceProvider);
21//! })
22//! .run()
23//! }
24//! ```
25//!
26//! Then set `MAIL_MAILER=lettermint` and `LETTERMINT_PROJECT_TOKEN`, and send email as usual:
27//!
28//! ```no_run
29//! use laravel::mail::{self, Message};
30//!
31//! # async fn example() -> laravel::Result<()> {
32//! mail::to("jane@example.com")
33//! .send(Message::new().subject("Welcome to Acme").html("<p>Thanks for signing up.</p>"))
34//! .await?;
35//! # Ok(()) }
36//! ```
37//!
38//! The [README](https://github.com/lettermint/lettermint-laravel-rust#readme) is the guide.
39
40mod config;
41mod error;
42pub mod events;
43mod http;
44mod options;
45mod provider;
46mod transport;
47pub mod webhooks;
48
49pub use config::{DRIVER, LettermintConfig, LettermintMailer, WebhookConfig};
50pub use error::{ConfigError, SendError};
51pub use options::Options;
52pub use provider::{LettermintServiceProvider, client as build_client, register};
53pub use transport::LettermintTransport;
54
55/// The Lettermint SDK, re-exported for its types.
56pub use lettermint;
57
58/// The application's Lettermint client, which the service provider registers.
59///
60/// ```no_run
61/// # async fn example() -> laravel::Result<()> {
62/// let lettermint = lettermint_laravel::client().await?;
63/// let domains = lettermint.domains().list(&Default::default()).await?;
64/// # let _ = domains;
65/// # Ok(()) }
66/// ```
67///
68/// In a handler, inject it with `Inject<Lettermint>` instead.
69///
70/// # Errors
71///
72/// Fails when the service provider isn't registered, or the SDK rejects the config.
73pub async fn client() -> laravel::Result<laravel::container::Inject<lettermint::Lettermint>> {
74 laravel::container::resolve::<lettermint::Lettermint>().await
75}
76
77/// Compiles the README examples as doctests.
78#[cfg(doctest)]
79#[doc = include_str!("../README.md")]
80pub struct ReadmeDoctests;