Skip to content

Commit 3fdf672

Browse files
authored
docs(service): document service utilities (#180)
this commit introduces some additional documentation to the `service` submodule, and the glue types like `TowerToHyperService` and `TowerToHyperServiceFuture`. links to relevant related documentation like `hyper::service`, and the documentation of `tower::Service`. this is closely related to hyperium/hyper#3869, which proposes a similar documentation pass over `hyper`'s own `service` facilities. Signed-off-by: katelyn martin <[email protected]>
1 parent 912dc78 commit 3fdf672

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

Diff for: src/service/glue.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,22 @@ use std::{
77

88
use super::Oneshot;
99

10-
/// A tower service converted into a hyper service.
10+
/// A tower [`Service`][tower-svc] converted into a hyper [`Service`][hyper-svc].
11+
///
12+
/// This wraps an inner tower service `S` in a [`hyper::service::Service`] implementation. See
13+
/// the module-level documentation of [`service`][crate::service] for more information about using
14+
/// [`tower`][tower] services and middleware with [`hyper`].
15+
///
16+
/// [hyper-svc]: hyper::service::Service
17+
/// [tower]: https://docs.rs/tower/latest/tower/
18+
/// [tower-svc]: https://docs.rs/tower/latest/tower/trait.Service.html
1119
#[derive(Debug, Copy, Clone)]
1220
pub struct TowerToHyperService<S> {
1321
service: S,
1422
}
1523

1624
impl<S> TowerToHyperService<S> {
17-
/// Create a new `TowerToHyperService` from a tower service.
25+
/// Create a new [`TowerToHyperService`] from a tower service.
1826
pub fn new(tower_service: S) -> Self {
1927
Self {
2028
service: tower_service,
@@ -39,6 +47,9 @@ where
3947

4048
pin_project! {
4149
/// Response future for [`TowerToHyperService`].
50+
///
51+
/// This future is acquired by [`call`][hyper::service::Service::call]ing a
52+
/// [`TowerToHyperService`].
4253
pub struct TowerToHyperServiceFuture<S, R>
4354
where
4455
S: tower_service::Service<R>,

Diff for: src/service/mod.rs

+21
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,25 @@
11
//! Service utilities.
2+
//!
3+
//! [`hyper::service`] provides a [`Service`][hyper-svc] trait, representing an asynchronous
4+
//! function from a `Request` to a `Response`. This provides an interface allowing middleware for
5+
//! network application to be written in a modular and reusable way.
6+
//!
7+
//! This submodule provides an assortment of utilities for working with [`Service`][hyper-svc]s.
8+
//! See the module-level documentation of [`hyper::service`] for more information.
9+
//!
10+
//! # Tower
11+
//!
12+
//! While [`hyper`] uses its own notion of a [`Service`][hyper-svc] internally, many other
13+
//! libraries use a library such as [`tower`][tower] to provide the fundamental model of an
14+
//! asynchronous function.
15+
//!
16+
//! The [`TowerToHyperService`] type provided by this submodule can be used to bridge these
17+
//! ecosystems together. By wrapping a [`tower::Service`][tower-svc] in [`TowerToHyperService`],
18+
//! it can be passed into [`hyper`] interfaces that expect a [`hyper::service::Service`].
19+
//!
20+
//! [hyper-svc]: hyper::service::Service
21+
//! [tower]: https://docs.rs/tower/latest/tower/
22+
//! [tower-svc]: https://docs.rs/tower/latest/tower/trait.Service.html
223
324
#[cfg(feature = "service")]
425
mod glue;

0 commit comments

Comments
 (0)