tackt/lib.rs
1//! # tackt
2//!
3//! > HTTP router for [tower][tower] service.
4//!
5//! ## usage overview
6//!
7//! ```rust
8//! use tackt::route;
9//! use tackt::routes;
10//!
11//! #[route(GET, PUT: "entity" / id / "resource" / path*)]
12//! async fn resource(
13//! req: http::Request<hyper::Body>,
14//! id: i32,
15//! path: String,
16//! ) -> Result<http::Response<hyper::Body>, Box<dyn std::error::Error>> {
17//! let content = format!("resource: {id} {path}");
18//! let body = hyper::Body::from(content);
19//! let response = http::Response::new(body);
20//! Ok(response)
21//! }
22//!
23//! let router = routes![resource];
24//! // use the `router` in `hyper::service::make_service_fn`.
25//! ```
26//!
27//! **NOTE**: `#[route]` attribute changes the function signature.
28//!
29//! ## route spec examples
30//!
31//! 1. Empty
32//!
33//! This spec will match exactly `"/"` on any methods.
34//!
35//! ```rust,ignore
36//! #[route]
37//! ```
38//!
39//! 1. Only methods
40//!
41//! This spec will match exactly `"/"` only on `GET` or `PUT` request.
42//!
43//! ```rust,ignore
44//! #[route(GET, PUT)]
45//! ```
46//!
47//! 1. Only segments
48//!
49//! This spec will match exactly `"/path/to/somewhere"` on any methods.
50//!
51//! ```rust,ignore
52//! #[route("path" / "to" / "somewhere")]
53//! ```
54//!
55//! 1. Methods and segments
56//!
57//! This spec will match exactly `"/path/to/somewhere"` only on `GET` request.
58//!
59//! ```rust,ignore
60//! #[route(GET: "path" / "to" / "somewhere")]
61//! ```
62//!
63//! ## route syntax:
64//!
65//! ```text
66//! spec: methods ':' segments
67//! / methods
68//! / segments
69//! / empty
70//!
71//! methods: identifier [',' identifier]*
72//!
73//! segments: segment ['/' segment]* ['/' rest]
74//!
75//! segment: literal-str / identifier
76//!
77//! rest: identifier '*'
78//!
79//! empty:
80//! ```
81//!
82//! [tower]: https://crates.io/crates/tower
83#![warn(
84 missing_docs,
85 missing_copy_implementations,
86 missing_debug_implementations,
87 unused_qualifications
88)]
89#![cfg_attr(docsrs, feature(doc_cfg))]
90
91mod error;
92mod func;
93mod future;
94mod macros;
95mod mount;
96mod or;
97mod param;
98mod request;
99mod route;
100mod router;
101mod void;
102mod with;
103
104#[cfg(test)]
105mod exec;
106
107pub use error::Error;
108pub use param::Param;
109pub use route::Route;
110pub use router::Router;
111pub use void::Void;
112
113pub use request::MethodReq;
114pub use request::PathReq;
115pub use request::RemovePrefix;
116
117pub use func::Func;
118pub use mount::Mount;
119pub use or::Or;
120
121pub use http::Method;
122pub use tower_service::Service;
123
124/// The attribute to describe route's spec.
125///
126/// See [the top-level documentation][lib].
127///
128/// [lib]: index.html
129#[cfg(feature = "macros")]
130#[cfg_attr(docsrs, doc(cfg(feature = "macros")))]
131pub use tackt_macros::route;
132
133/// Derive [`Param`][crate::param::Param] for struct.
134///
135/// See [`Param` doc][crate::param::Param].
136#[cfg(feature = "macros")]
137#[cfg_attr(docsrs, doc(cfg(feature = "macros")))]
138pub use tackt_macros::Param;