Skip to main content

churust_core/
lib.rs

1//! Churust core kernel: the engine, routing, request pipeline, and extractors
2//! that power the [Churust](https://crates.io/crates/churust) web framework.
3//!
4//! Churust is a Ktor-inspired, async-first web framework for Rust. This crate
5//! (`churust-core`) is the foundation every other Churust crate builds on. It
6//! provides:
7//!
8//! - A fluent [`Churust::server`] builder ([`AppBuilder`]) for assembling an
9//!   [`App`] from routes, shared state, middleware, and configuration.
10//! - A trie-based [`Router`] supporting static segments, `{param}` captures, and
11//!   trailing `{name...}` wildcards.
12//! - The per-request [`Call`] context — the single object every handler receives.
13//! - An onion-style middleware [pipeline] ordered by [`Phase`].
14//! - Type-safe [extractors](crate::extract) ([`Path`], [`Query`], [`State`],
15//!   [`BearerToken`]) plus the [`FromCall`]/[`FromCallParts`] traits that let
16//!   handlers take typed arguments.
17//! - A flexible [`Response`]/[`IntoResponse`] model and a status-carrying
18//!   [`Error`] type.
19//! - Layered [`Config`] loading (defaults < `churust.toml` < `CHURUST_*` env <
20//!   code) and optional TLS (feature `tls`).
21//! - An in-process [`TestClient`] for fast, socket-free integration tests.
22//!
23//! # Example
24//!
25//! Build an app, register a route, and exercise it with the in-process test
26//! client (no socket is bound, so this runs in any environment):
27//!
28//! ```
29//! use churust_core::{Churust, Call, TestClient};
30//! # tokio::runtime::Runtime::new().unwrap().block_on(async {
31//! let app = Churust::server()
32//!     .routing(|r| {
33//!         r.get("/", |_c: Call| async { "Hello, Churust!" });
34//!     })
35//!     .build();
36//!
37//! let res = TestClient::new(app).get("/").send().await;
38//! assert_eq!(res.status().as_u16(), 200);
39//! assert_eq!(res.text(), "Hello, Churust!");
40//! # });
41//! ```
42//!
43//! To actually serve traffic, call [`App::start`] (binds a socket and serves
44//! until Ctrl-C) or [`AppBuilder::start`].
45
46#![deny(missing_docs)]
47#![doc(
48    html_logo_url = "https://raw.githubusercontent.com/davthecoder/Churust/main/img/churust_logo.png"
49)]
50
51pub mod body;
52pub use body::Body;
53
54pub mod error;
55pub use error::{Error, Result};
56
57pub mod response;
58pub use response::{IntoResponse, Response};
59
60pub mod call;
61pub use call::Call;
62
63pub mod handler;
64pub use handler::{boxed, BoxHandler, Handler, IntoHandler};
65
66pub mod state;
67pub use state::StateMap;
68
69pub mod extract;
70pub use extract::{BearerToken, FromCall, FromCallParts, Path, Query, State};
71
72pub mod router;
73pub use router::{Match, RouteBuilder, Router};
74
75pub mod pipeline;
76pub use pipeline::{Endpoint, Middleware, Next, Phase};
77
78pub mod config;
79pub use config::{Config, ServerSection, TlsSection};
80
81pub mod app;
82pub use app::{App, AppBuilder, Churust, Plugin, ServerConfig};
83
84pub mod engine;
85
86#[cfg(feature = "tls")]
87pub mod tls;
88
89#[cfg(feature = "ws")]
90pub mod ws;
91#[cfg(feature = "ws")]
92pub use ws::{WebSocket, WebSocketUpgrade};
93
94#[cfg(feature = "fs")]
95pub mod fs;
96#[cfg(feature = "fs")]
97pub use fs::StaticFiles;
98
99pub mod test;
100pub use test::{TestClient, TestRequest, TestResponse};
101
102#[cfg(test)]
103mod smoke {
104    #[test]
105    fn workspace_builds() {
106        assert_eq!(2 + 2, 4);
107    }
108}