unit_rs/lib.rs
1//! # unit-rs
2//!
3//! `unit-rs` is a safe wrapper around the C `libunit` library from [NGINX Unit],
4//! which allows creating Unit applications in Rust.
5//!
6//! [NGINX Unit]: https://unit.nginx.org/
7//!
8//! ## Example
9//!
10//! ```no_run
11//! use unit_rs::{Unit, Request};
12//!
13//! fn main() {
14//! let mut unit = Unit::new().unwrap();
15//!
16//! unit.set_request_handler(|req: Request<'_>| {
17//! let headers = &[("Content-Type", "text/plain")];
18//! let body = "Hello world!\n";
19//! req.send_response(200, headers, body)?;
20//!
21//! Ok(())
22//! });
23//!
24//! unit.run();
25//! }
26//! ```
27//!
28//! ## Features
29//!
30//! Currently not all features are supported, but enough are available to
31//! inspect all aspects of a request and create a response.
32//!
33//! This library is also capable of multi-threading by creating additional
34//! instances of [`Unit`].
35//!
36//! When the `http` feature enabled, the [`http::HttpHandler`] adapter can be
37//! used to write handlers using types from the [`http`](https://docs.rs/http)
38//! crate.
39//!
40//! ## Missing features
41//!
42//! WebSockets support is not yet implemented.
43//!
44//! A callback for inspecting a request header (and potentially closing the
45//! request) before Unit buffers the whole request body is not yet available.
46//!
47//! There is currently no way to perform asynchronous handling of requests.
48//! Handlers with expensive computations or blocking IO will block the whole
49//! thread context.
50
51#![cfg_attr(docsrs, feature(doc_cfg))]
52
53mod error;
54#[cfg(feature = "http")]
55#[cfg_attr(docsrs, doc(cfg(feature = "http")))]
56pub mod http;
57mod nxt_unit;
58mod request;
59mod response;
60mod unit;
61
62pub use error::{UnitError, UnitInitError, UnitResult};
63pub use request::{BodyReader, Request};
64pub use response::{BodyWriter, Response};
65pub use unit::{Unit, UnitService};