Skip to content

Commit

Permalink
Add conditional compilation flags for email clients
Browse files Browse the repository at this point in the history
Features such as "mailersend", "terminal", "smtp", "memory", and "document-features" on certain imports and functions have been added. This enables these functionalities to be included or excluded at compile-time, depending on the required configuration. This provides greater flexibility and can optimize the build size and time for different usage scenarios.
  • Loading branch information
amritghimire committed Apr 28, 2024
1 parent ae56080 commit a2ac525
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/clients/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#[cfg(any(feature = "mailersend", feature = "terminal", feature = "smtp", feature = "memory", feature = "document-features"))]
use crate::configuration::EmailConfiguration;
#[cfg(any(feature = "mailersend", feature = "terminal", feature = "smtp", feature = "memory", feature = "document-features"))]
use crate::traits::EmailTrait;

#[cfg_attr(docsrs, doc(cfg(feature = "smtp")))]
Expand All @@ -17,6 +19,7 @@ pub mod terminal;
#[cfg(feature = "mailersend")]
pub mod mailersend;

#[cfg(any(feature = "mailersend", feature = "terminal", feature = "smtp", feature = "memory", feature = "document-features"))]
///`EmailClient` Enum representing different types of email clients.
///Currently supported email clients: SMTP, Terminal, Memory.
///
Expand Down Expand Up @@ -94,6 +97,7 @@ impl Default for EmailClient {
}
}

#[cfg(any(feature = "mailersend", feature = "terminal", feature = "smtp", feature = "memory", feature = "document-features"))]
pub fn get_email_client(configuration: EmailConfiguration) -> EmailClient {
match configuration {
#[cfg(feature = "terminal")]
Expand All @@ -111,6 +115,7 @@ pub fn get_email_client(configuration: EmailConfiguration) -> EmailClient {
}
}

#[cfg(any(feature = "mailersend", feature = "terminal", feature = "smtp", feature = "memory", feature = "document-features"))]
impl EmailClient {
/// Unwrap the `EmailClient` enum variant and convert it into a `Box<dyn EmailTrait + Send>`.
///
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
//!
//!```rust
//! use std::sync::mpsc;
//! # #[cfg(any(feature = "mailersend", feature = "terminal", feature = "smtp", feature = "memory", feature = "document-features"))]
//! use email_clients::clients::{EmailClient, get_email_client};
//! # #[cfg(feature = "mailersend")]
//! use email_clients::clients::mailersend::MailerSendConfig;
//! # #[cfg(feature = "memory")]
//! use email_clients::clients::memory::{MemoryClient, MemoryConfig};
Expand Down
2 changes: 2 additions & 0 deletions tests/clients.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#[cfg(any(feature = "mailersend", feature = "terminal", feature = "smtp", feature = "memory", feature = "document-features"))]
use email_clients::clients::get_email_client;
#[cfg(feature = "memory")]
use email_clients::clients::memory::MemoryConfig;
#[cfg(feature = "smtp")]
use email_clients::clients::smtp::SmtpConfig;
#[cfg(any(feature = "mailersend", feature = "terminal", feature = "smtp", feature = "memory", feature = "document-features"))]
use email_clients::configuration::EmailConfiguration;

#[cfg(feature = "terminal")]
Expand Down

0 comments on commit a2ac525

Please sign in to comment.