Skip to main content

trillium/
lib.rs

1#![forbid(unsafe_code)]
2#![deny(
3    clippy::dbg_macro,
4    missing_copy_implementations,
5    rustdoc::missing_crate_level_docs,
6    missing_debug_implementations,
7    nonstandard_style,
8    unused_qualifications
9)]
10#![warn(missing_docs, clippy::pedantic, clippy::nursery, clippy::cargo)]
11#![allow(
12    clippy::must_use_candidate,
13    clippy::module_name_repetitions,
14    clippy::multiple_crate_versions
15)]
16
17//! # Welcome to the `trillium` crate!
18//!
19//! This crate is the primary dependency for building a trillium app or
20//! library. It contains a handful of core types and reexports a few
21//! others that you will necessarily need, but otherwise tries to stay
22//! small and focused.
23//!
24//! To get started with this crate, first take a look at [the
25//! guide](https://trillium.rs), then browse the docs for
26//! [`trillium::Conn`](crate::Conn).
27//!
28//! At a minimum to build a trillium app, you'll also need a trillium
29//! [runtime adapter](https://trillium.rs/overview/runtimes.html).
30
31#[cfg(test)]
32#[doc = include_str!("../README.md")]
33mod readme {}
34
35mod handler;
36pub use handler::Handler;
37
38mod conn;
39pub use conn::Conn;
40
41mod state;
42pub use state::{State, state};
43pub use trillium_http::{
44    Body, BodySource, Error, HeaderName, HeaderValue, HeaderValues, Headers, HttpConfig,
45    HttpContext, KnownHeaderName, Method, Status, Swansong, TypeSet, Version,
46};
47
48mod transport;
49pub use transport::Transport;
50
51mod upgrade;
52pub use upgrade::Upgrade;
53
54mod macros;
55
56pub use log;
57
58mod info;
59pub use info::Info;
60
61mod boxed_handler;
62pub use boxed_handler::BoxedHandler;
63
64mod init;
65pub use init::{Init, init};
66
67/// Types for interacting with [`Headers`]
68pub mod headers {
69    use crate::{CRATE_VERSION, HeaderValue};
70    use std::sync::LazyLock;
71    use trillium_http::CRATE_VERSION as HTTP_CRATE_VERSION;
72    pub use trillium_http::headers::{Entry, IntoIter, Iter};
73
74    /// Returns the default server header value for trillium, including both the
75    /// `trillium` and `trillium-http` crate versions.
76    ///
77    /// The contents are necessarily unconstrained by semver.
78    pub fn server_header() -> HeaderValue {
79        static SERVER_HEADER: LazyLock<HeaderValue> = LazyLock::new(|| {
80            let s: &'static str =
81                format!("trillium/{CRATE_VERSION} trillium-http/{HTTP_CRATE_VERSION}").leak();
82            s.into()
83        });
84
85        SERVER_HEADER.clone()
86    }
87}
88
89/// Types for interacting with [`TypeSet`]
90pub mod type_set {
91    pub use trillium_http::type_set::entry::Entry;
92}
93
94mod request_body;
95pub use request_body::RequestBody;
96
97/// The version of this crate
98pub const CRATE_VERSION: &str = env!("CARGO_PKG_VERSION");