rspamd_client/
lib.rs

1//!# Rspamd Client for Rust
2//!
3//! This crate provides an HTTP client for interacting with the Rspamd service in Rust.
4//! It supports both synchronous and asynchronous operations using the `attohttpc` and
5//! `reqwest` libraries, respectively.
6//!
7//! ## Features
8//!
9//! - **Sync**: Synchronous client using `attohttpc`.
10//! - **Async**: Asynchronous client using `reqwest`.
11//! - Easily configurable with support for proxy, encryption, TLS and ZSTD compression.
12//! - Supports scanning emails for spam scores and other metrics.
13
14// Ensure async and sync features are mutually exclusive
15#[cfg(all(feature = "async", feature = "sync"))]
16compile_error!("Features 'async' and 'sync' are mutually exclusive. Please enable only one.");
17
18#[cfg(not(any(feature = "async", feature = "sync")))]
19compile_error!("Either 'async' or 'sync' feature must be enabled.");
20
21pub mod config;
22pub mod error;
23pub mod protocol;
24
25pub mod backend;
26
27#[cfg(feature = "sync")]
28pub use backend::sync_client::scan_sync;
29/// ### Synchronous Client
30///
31/// This example demonstrates how to scan an email using the synchronous client.
32///
33/// ```rust,no_run
34/// use rspamd_client::{config, scan_sync};
35///
36/// let config = config::Config::builder()
37///     .base_url("http://localhost:11333".to_string())
38///     .build();
39/// let email = "From: user@example.com\nTo: recipient@example.com\nSubject: Test\n\nThis is a test email.";
40///
41/// match scan_sync(&config, email, Default::default()) {
42///     Ok(response) => println!("Scan result: {:?}", response),
43///     Err(e) => eprintln!("Error scanning email: {}", e),
44/// }
45/// ```
46///
47#[cfg(feature = "sync")]
48pub use backend::sync_client::SyncClient;
49
50#[cfg(feature = "async")]
51pub use backend::async_client::scan_async;
52/// ### Asynchronous Client
53///
54/// This example demonstrates how to scan an email using the asynchronous client.
55///
56/// ```rust,no_run
57/// use rspamd_client::{config, scan_async};
58/// # use tokio;
59///
60/// # #[tokio::main]
61/// # async fn main() {
62/// let config = config::Config::builder()
63///     .base_url("http://localhost:11333".to_string())
64///     .build();
65/// let email = "From: user@example.com\nTo: recipient@example.com\nSubject: Test\n\nThis is a test email.";
66///
67/// match scan_async(&config, email, Default::default()).await {
68///     Ok(response) => println!("Scan result: {:?}", response),
69///     Err(e) => eprintln!("Error scanning email: {}", e),
70/// }
71/// # }
72/// ```
73#[cfg(feature = "async")]
74pub use backend::async_client::AsyncClient;