catalyzer/internals/
handlers.rs

1pub use ::axum::handler::Handler as AxumHandler;
2pub use ::tower::Service as TowerService;
3pub use ::axum::http::Method;
4
5use core::convert::Infallible;
6use crate::req::RawRequest;
7
8/// A trait that represents a handler metadata.
9/// 
10/// They are used to store the metadata of a handler,
11/// and are automatically implemented by the `#[get]`, `#[post]`, etc. macros.
12/// 
13/// This trait is used internally by Catalyzer, and should not be implemented manually.
14/// 
15/// With `#[get]`:
16/// 
17/// ```rust
18/// # use catalyzer::*;
19/// #[get("/")]
20/// fn index() {
21///     "Hello, world!"
22/// }
23/// ```
24/// 
25/// Manual implementation:
26/// 
27/// ```rust
28/// # use catalyzer::*;
29/// async fn index() -> impl ::catalyzer::res::IntoRawResponse {
30///     "Hello, world!"
31/// }
32/// #[doc(hidden)]
33/// #[repr(transparent)]
34/// #[allow(non_camel_case_types)]
35/// struct index_metadata;
36/// impl ::catalyzer::internals::HandlerMetadata for index_metadata {
37///     const PATH: &'static str = "/";
38///     const METHOD: ::catalyzer::internals::Method = ::catalyzer::internals::Method::GET;
39/// }
40/// ```
41pub trait HandlerMetadata {
42    /// Path to mount the handler on.
43    const PATH: &'static str;
44    /// Method to handle.
45    const METHOD: Method;
46}
47
48/// A trait that represents a Catalyzer service.
49/// 
50/// All services must implement this trait (and the [`TowerService`] trait).
51/// 
52/// [`TowerService`]: https://docs.rs/tower/0.4.4/tower/trait.Service.html
53pub trait CatalyzerService: TowerService<RawRequest, Error = Infallible> {
54    /// Path to mount the service on.
55    const PATH: &'static str;
56}