serwus/
lib.rs

1//! Serwus is a set of helpers for building actix-web/diesel based services.
2//!
3//! ## Features
4//!
5//! * **[MultiPool](db_pool::multi::MultiPool)** - Master/replica-aware wrapper for `r2d2`
6//! * **[StatsPresenter](server::stats::StatsPresenter)** - Framework for readiness and statistics reporting
7//! * **[JsonError](server::json_error::JsonError)** - Middleware that makes actix-web return errors as JSONs
8//!
9//! ## Example
10//!
11//! ```no_run
12//! use serwus::{
13//!     server::{Serwus, default_cors},
14//!     EmptyStats,
15//!     web,
16//! };
17//!
18//! #[derive(Clone, EmptyStats)]
19//! pub struct AppData;
20//!
21//! # #[cfg_attr(feature = "swagger", paperclip::actix::api_v2_operation)]
22//! async fn hello() -> &'static str {
23//!     "Hello world\n"
24//! }
25//!
26//! #[actix_web::main]
27//! async fn main() -> std::io::Result<()> {
28//!     let prepare_app_data = || AppData;
29//!
30//!     Serwus::default()
31//!         .start(
32//!             prepare_app_data,
33//!             |app| {
34//!                 app.route("/", web::get().to(hello));
35//!             },
36//!             default_cors,
37//!         )
38//!         .await
39//! }
40//! ```
41
42#![deny(clippy::all)]
43
44pub mod containers;
45pub mod utils;
46
47pub mod auth;
48#[cfg(any(feature = "pgsql", feature = "mysql"))]
49pub mod db_pool;
50
51pub mod server;
52
53pub mod return_logged;
54
55pub mod threads;
56
57#[cfg(any(feature = "pgsql", feature = "mysql"))]
58pub mod pagination;
59
60pub mod logger;
61
62/// Re-export of `web` from `actix-web` or from `paperclip` if swagger feature enabled.
63#[cfg(not(feature = "swagger"))]
64pub use actix_web::web;
65#[cfg(feature = "swagger")]
66pub use paperclip::actix::web;
67
68/// Automatic implementation of [StatsPresenter](server::stats::StatsPresenter)
69///
70/// Returns `()` as stats, and always repors as ready.
71pub use serwus_derive::EmptyStats;