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 listeners;
62pub use listeners::{Listener, ListenerKind, Listeners};
63
64mod boxed_handler;
65pub use boxed_handler::BoxedHandler;
66
67mod init;
68pub use init::{Init, init};
69
70/// Types for interacting with [`Headers`]
71pub mod headers {
72    use crate::{CRATE_VERSION, HeaderValue};
73    use std::sync::LazyLock;
74    use trillium_http::CRATE_VERSION as HTTP_CRATE_VERSION;
75    pub use trillium_http::headers::{Entry, IntoIter, Iter};
76
77    /// Returns the default server header value for trillium, including both the
78    /// `trillium` and `trillium-http` crate versions.
79    ///
80    /// The contents are necessarily unconstrained by semver.
81    pub fn server_header() -> HeaderValue {
82        static SERVER_HEADER: LazyLock<HeaderValue> = LazyLock::new(|| {
83            let s: &'static str =
84                format!("trillium/{CRATE_VERSION} trillium-http/{HTTP_CRATE_VERSION}").leak();
85            s.into()
86        });
87
88        SERVER_HEADER.clone()
89    }
90}
91
92/// Types for interacting with [`TypeSet`]
93pub mod type_set {
94    pub use trillium_http::type_set::entry::Entry;
95}
96
97mod request_body;
98pub use request_body::RequestBody;
99
100/// The version of this crate
101pub const CRATE_VERSION: &str = env!("CARGO_PKG_VERSION");