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