1 //! Asynchronous Services 2 //! 3 //! A [`Service`](Service) is a trait representing an asynchronous 4 //! function of a request to a response. It's similar to 5 //! `async fn(Request) -> Result<Response, Error>`. 6 //! 7 //! The argument and return value isn't strictly required to be for HTTP. 8 //! Therefore, hyper uses several "trait aliases" to reduce clutter around 9 //! bounds. These are: 10 //! 11 //! - `HttpService`: This is blanketly implemented for all types that 12 //! implement `Service<http::Request<B1>, Response = http::Response<B2>>`. 13 //! - `MakeService`: When a `Service` returns a new `Service` as its "response", 14 //! we consider it a `MakeService`. Again, blanketly implemented in those cases. 15 //! - `MakeConnection`: A `Service` that returns a "connection", a type that 16 //! implements `AsyncRead` and `AsyncWrite`. 17 //! 18 //! # HttpService 19 //! 20 //! In hyper, especially in the server setting, a `Service` is usually bound 21 //! to a single connection. It defines how to respond to **all** requests that 22 //! connection will receive. 23 //! 24 //! The helper [`service_fn`](service_fn) should be sufficient for most cases, but 25 //! if you need to implement `Service` for a type manually, you can follow the example 26 //! in `service_struct_impl.rs`. 27 //! 28 //! # MakeService 29 //! 30 //! Since a `Service` is bound to a single connection, a [`Server`](crate::Server) 31 //! needs a way to make them as it accepts connections. This is what a 32 //! `MakeService` does. 33 //! 34 //! Resources that need to be shared by all `Service`s can be put into a 35 //! `MakeService`, and then passed to individual `Service`s when `call` 36 //! is called. 37 38 pub use tower_service::Service; 39 40 mod http; 41 mod make; 42 #[cfg(all(any(feature = "http1", feature = "http2"), feature = "client"))] 43 mod oneshot; 44 mod util; 45 46 pub(super) use self::http::HttpService; 47 #[cfg(all(any(feature = "http1", feature = "http2"), feature = "client"))] 48 pub(super) use self::make::MakeConnection; 49 #[cfg(all(any(feature = "http1", feature = "http2"), feature = "server"))] 50 pub(super) use self::make::MakeServiceRef; 51 #[cfg(all(any(feature = "http1", feature = "http2"), feature = "client"))] 52 pub(super) use self::oneshot::{oneshot, Oneshot}; 53 54 pub use self::make::make_service_fn; 55 pub use self::util::service_fn; 56