rustapi_extras/
lib.rs

1//! # rustapi-extras
2//!
3//! Optional security and utility features for the RustAPI framework.
4//!
5//! This crate provides production-ready middleware and utilities that are
6//! opt-in via Cargo feature flags to minimize binary size when not needed.
7//!
8//! ## Features
9//!
10//! - `jwt` - JWT authentication middleware and `AuthUser<T>` extractor
11//! - `cors` - CORS middleware with builder pattern configuration
12//! - `rate-limit` - IP-based rate limiting middleware
13//! - `config` - Configuration management with `.env` file support
14//! - `cookies` - Cookie parsing extractor
15//! - `sqlx` - SQLx database error conversion to ApiError
16//! - `extras` - Meta feature enabling jwt, cors, and rate-limit
17//! - `full` - All features enabled
18//!
19//! ## Example
20//!
21//! ```toml
22//! [dependencies]
23//! rustapi-extras = { version = "0.1", features = ["jwt", "cors"] }
24//! ```
25
26#![warn(missing_docs)]
27#![warn(rustdoc::missing_crate_level_docs)]
28
29// JWT authentication module
30#[cfg(feature = "jwt")]
31pub mod jwt;
32
33// CORS middleware module
34#[cfg(feature = "cors")]
35pub mod cors;
36
37// Rate limiting module
38#[cfg(feature = "rate-limit")]
39pub mod rate_limit;
40
41// Configuration management module
42#[cfg(feature = "config")]
43pub mod config;
44
45// SQLx database integration module
46#[cfg(feature = "sqlx")]
47pub mod sqlx;
48
49// Re-exports for convenience
50#[cfg(feature = "jwt")]
51pub use jwt::{create_token, AuthUser, JwtError, JwtLayer, JwtValidation, ValidatedClaims};
52
53#[cfg(feature = "cors")]
54pub use cors::{AllowedOrigins, CorsLayer};
55
56#[cfg(feature = "rate-limit")]
57pub use rate_limit::RateLimitLayer;
58
59#[cfg(feature = "config")]
60pub use config::{
61    env_or, env_parse, load_dotenv, load_dotenv_from, require_env, Config, ConfigError, Environment,
62};
63
64#[cfg(feature = "sqlx")]
65pub use sqlx::{convert_sqlx_error, SqlxErrorExt};