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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
//! Opinionated async Rust for IO-bound services on top of Tokio.
//!
//! Camber is for the common case: HTTP services, background jobs, proxying,
//! and runtime-scoped work where you want Tokio underneath without building
//! your whole application around Tower, extractors, or a custom runtime setup.
//!
//! # Start Here
//!
//! The normal entrypoint is [`http::serve`]:
//!
//! ```rust,no_run
//! use camber::RuntimeError;
//! use camber::http::{self, Response, Router};
//!
//! fn main() -> Result<(), RuntimeError> {
//! let mut router = Router::new();
//! router.get("/hello", |_req| async {
//! Response::text(200, "Hello, world!")
//! });
//! http::serve("0.0.0.0:8080", router)
//! }
//! ```
//!
//! Use [`runtime::builder`] when you need runtime configuration around that
//! service, such as worker counts, shutdown timeouts, connection limits, or
//! registered resources:
//!
//! ```rust,no_run
//! use camber::{RuntimeError, runtime};
//! use std::time::Duration;
//!
//! fn main() -> Result<(), RuntimeError> {
//! runtime::builder()
//! .worker_threads(8)
//! .shutdown_timeout(Duration::from_secs(10))
//! .run(|| Ok::<(), RuntimeError>(()))?
//! }
//! ```
//!
//! # Core Model
//!
//! Camber keeps the public model small:
//!
//! - [`http::Router`] registers handlers and middleware
//! - [`http::Request`] provides string-based access to params, query, headers,
//! cookies, and body
//! - [`http::Response`] builds owned HTTP responses
//! - [`spawn`] and [`spawn_async`] run structured background work
//! - [`Resource`] integrates long-lived dependencies into startup, health
//! checks, and shutdown
//!
//! Handlers are async closures over `&Request`:
//!
//! ```rust
//! use camber::http::{Request, Response, Router};
//!
//! let mut router = Router::new();
//! router.get("/users/:id", |req: &Request| {
//! let user_id = match req.param("id") {
//! Some(id) => id.to_owned(),
//! None => String::new(),
//! };
//! async move {
//! Response::text(200, &user_id)
//! }
//! });
//! ```
//!
//! If you need request data after an `.await`, copy owned data out before the
//! `async move`. The returned future must be `Send + 'static`.
//!
//! # Main Modules
//!
//! - [`http`]: servers, router, requests, responses, middleware, client, SSE,
//! and proxying
//! - [`runtime`]: runtime configuration, shutdown, and lifecycle entrypoints
//! - [`task`]: structured task spawning, cancellation, and shutdown waiting
//! - [`channel`]: bounded sync channels and async MPSC channels
//! - [`resource`]: resource lifecycle integration
//! - [`schedule`]: interval and cron-style scheduled work
//! - [`net`]: low-level listeners, TCP, UDP, and forwarding
//! - [`tls`]: certificate loading, TLS config, and client connections
//! - [`logging`]: tracing subscriber setup helpers
//! - [`config`]: TOML config loading and shared TLS config types
//!
//! # Error Model
//!
//! Camber uses [`RuntimeError`] at the runtime boundary. Most top-level APIs
//! return `Result<_, RuntimeError>`, so library code can use normal `?`
//! propagation without mapping between framework-specific error types.
//!
//! # Feature Flags
//!
//! Optional capabilities are feature-gated:
//!
//! - `ws`: WebSocket routes
//! - `grpc`: gRPC serving support
//! - `otel`: OpenTelemetry tracing and export
//! - `acme`: automatic TLS via ACME
//! - `dns01`: ACME DNS-01 support
//! - `nats`, `sqs`: message queue integrations
//!
//! # Choosing Camber
//!
//! Camber is a good fit when:
//!
//! - your service is IO-bound
//! - you want explicit request and response handling
//! - you want Tokio underneath but not Tokio ceremony everywhere
//! - you prefer a small built-in surface over assembling many crates up front
//!
//! If you need fine-grained executor control, Tower-heavy composition, or a
//! lower-level transport stack, use Tokio and its surrounding ecosystem
//! directly.
//!
compile_error!;
static GLOBAL: Jemalloc = Jemalloc;
static GLOBAL: MiMalloc = MiMalloc;
/// Automatic TLS via ACME.
/// Sync and async channel primitives.
/// Circuit breaker wrapper for managed resources.
/// Shared config parsing and TLS config types.
/// ACME DNS-01 support for automatic TLS.
/// Common runtime error type.
/// Tracing subscriber setup helpers.
/// Message queue integrations.
/// Low-level networking APIs.
pub
/// Resource lifecycle integration.
pub
/// Runtime configuration and shutdown control.
pub
/// Interval and cron-style scheduling.
/// Secret loading helpers.
/// OS signal helpers.
/// Structured task spawning and coordination.
/// Timeout helpers.
/// TLS certificate and connection helpers.
pub use AcmeConfig;
pub use test;
pub use RuntimeError;
pub use Resource;
pub use RuntimeBuilder;
pub use on_cancel;
pub use ;
pub use timeout;
pub use CertStore;
pub use tracing;
/// Internal re-exports for macro hygiene. Not part of the public API.