Skip to content

Commit a2ac525

Browse files
committed
Add conditional compilation flags for email clients
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.
1 parent ae56080 commit a2ac525

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

src/clients/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
#[cfg(any(feature = "mailersend", feature = "terminal", feature = "smtp", feature = "memory", feature = "document-features"))]
12
use crate::configuration::EmailConfiguration;
3+
#[cfg(any(feature = "mailersend", feature = "terminal", feature = "smtp", feature = "memory", feature = "document-features"))]
24
use crate::traits::EmailTrait;
35

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

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

100+
#[cfg(any(feature = "mailersend", feature = "terminal", feature = "smtp", feature = "memory", feature = "document-features"))]
97101
pub fn get_email_client(configuration: EmailConfiguration) -> EmailClient {
98102
match configuration {
99103
#[cfg(feature = "terminal")]
@@ -111,6 +115,7 @@ pub fn get_email_client(configuration: EmailConfiguration) -> EmailClient {
111115
}
112116
}
113117

118+
#[cfg(any(feature = "mailersend", feature = "terminal", feature = "smtp", feature = "memory", feature = "document-features"))]
114119
impl EmailClient {
115120
/// Unwrap the `EmailClient` enum variant and convert it into a `Box<dyn EmailTrait + Send>`.
116121
///

src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
//!
1616
//!```rust
1717
//! use std::sync::mpsc;
18+
//! # #[cfg(any(feature = "mailersend", feature = "terminal", feature = "smtp", feature = "memory", feature = "document-features"))]
1819
//! use email_clients::clients::{EmailClient, get_email_client};
20+
//! # #[cfg(feature = "mailersend")]
1921
//! use email_clients::clients::mailersend::MailerSendConfig;
2022
//! # #[cfg(feature = "memory")]
2123
//! use email_clients::clients::memory::{MemoryClient, MemoryConfig};

tests/clients.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
#[cfg(any(feature = "mailersend", feature = "terminal", feature = "smtp", feature = "memory", feature = "document-features"))]
12
use email_clients::clients::get_email_client;
23
#[cfg(feature = "memory")]
34
use email_clients::clients::memory::MemoryConfig;
45
#[cfg(feature = "smtp")]
56
use email_clients::clients::smtp::SmtpConfig;
7+
#[cfg(any(feature = "mailersend", feature = "terminal", feature = "smtp", feature = "memory", feature = "document-features"))]
68
use email_clients::configuration::EmailConfiguration;
79

810
#[cfg(feature = "terminal")]

0 commit comments

Comments
 (0)