1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
//! Actix Tower — Bringing the Rust Web Ecosystem to Actix Web
//!
//! A collection of extensions that modernize the Actix Web ecosystem
//! while preserving its performance and stability.
//!
//! Actix Tower — Bridging the Rust Web Ecosystem
//!
//! A collection of extensions that modernize the Actix Web ecosystem by allowing
//! developers to tap directly into the broader `tower` and `tower-http` middleware
//! ecosystem without sacrificing Actix Web's raw performance.
//!
//! # Core Features
//!
//! - **Tower Compatibility**: Safely wraps `Send + Sync` Tower middleware around `!Send` Actix workers.
//! - **Ergonomic Extractors**: `AutoJson`, `AutoQuery`, and `AutoPath` to drastically reduce boilerplate.
//! - **Production Middleware**: Built-in rate limiting, response caching, timeouts, and structured tracing.
//! - **Typed Responses**: A standardized `ApiResponse` envelope and `ApiError` utility.
//!
//! # Quick Start: The Ultimate Microservice
//!
//! This crate allows you to mix native Actix middleware with native Tower middleware seamlessly:
//!
//! ```no_run
//! use actix_web::{App, web, HttpResponse};
//! use actix_tower::prelude::*;
//! use tower_http::timeout::TimeoutLayer;
//! use tower_http::trace::TraceLayer;
//! use std::time::Duration;
//!
//! async fn handler(body: AutoJson<serde_json::Value>) -> actix_web::Result<HttpResponse> {
//! Ok(HttpResponse::Ok().json(body.into_inner()))
//! }
//!
//! let app = App::new()
//! // 1. Tower Trace (Logging)
//! .wrap(TowerLayerCompat::new(TraceLayer::new_for_http()))
//! // 2. Tower Timeout (Abort slow requests)
//! .wrap(TowerLayerCompat::new(TimeoutLayer::new(Duration::from_secs(5))))
//! // 3. Native Actix Tower Rate Limit (10 reqs/sec per IP)
//! .wrap(RateLimit::new(10, Duration::from_secs(1)))
//! .route("/", web::post().to(handler));
//! ```
//!
//! # Understanding the Concurrency Bridge
//!
//! Integrating Tower into Actix is difficult because Tower expects `Service::Future: Send`
//! (enabling tasks to move between threads), whereas Actix Web workers execute on a thread-local runtime (`!Send`).
//!
//! `actix_tower` bridges this gap safely using a custom `TowerMiddlewareService` wrapper.
//! By isolating the `Tower` layer inside a thread-local `Rc<RefCell<..>>` pool, it satisfies
//! Tower's `poll_ready` contracts without risking concurrency deadlocks on the Actix runtime.
// ---------------------------------------------------------------------------
// Re-exports
// ---------------------------------------------------------------------------
/// Re-export of actix_web for convenience.
pub use actix_web;
/// Re-export of tower for convenience.
pub use tower;
/// Re-export of http for convenience.
pub use http;
/// A type-erased, `Send + Sync` error pointer — the canonical Tower error type.
///
/// This is the same type used throughout `tower`, `tower-http`, `axum`, and
/// `hyper`. Custom Tower middleware should use this as `Service::Error`.
pub use crateBoxError;
/// The toolkit version.
pub const VERSION: &str = env!;
/// The toolkit crate name.
pub const NAME: &str = env!;