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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#![doc(html_root_url = "https://docs.rs/tower-util/0.3.0")]
#![warn(
missing_debug_implementations,
missing_docs,
rust_2018_idioms,
unreachable_pub
)]
#![allow(elided_lifetimes_in_paths)]
mod boxed;
#[cfg(feature = "call-all")]
mod call_all;
mod either;
mod oneshot;
mod optional;
mod ready;
mod service_fn;
pub use crate::{
boxed::{BoxService, UnsyncBoxService},
either::Either,
oneshot::Oneshot,
optional::Optional,
ready::Ready,
service_fn::{service_fn, ServiceFn},
};
#[cfg(feature = "call-all")]
pub use crate::call_all::{CallAll, CallAllUnordered};
#[doc(hidden)]
pub type Error = Box<dyn std::error::Error + Send + Sync>;
pub mod error {
pub use crate::optional::error as optional;
}
pub mod future {
pub use crate::optional::future as optional;
}
pub trait ServiceExt<Request>: tower_service::Service<Request> {
fn ready(&mut self) -> Ready<'_, Self, Request>
where
Self: Sized,
{
Ready::new(self)
}
fn oneshot(self, req: Request) -> Oneshot<Self, Request>
where
Self: Sized,
{
Oneshot::new(self, req)
}
#[cfg(feature = "call-all")]
fn call_all<S>(self, reqs: S) -> CallAll<Self, S>
where
Self: Sized,
Self::Error: Into<Error>,
S: futures_core::Stream<Item = Request>,
{
CallAll::new(self, reqs)
}
}
impl<T: ?Sized, Request> ServiceExt<Request> for T where T: tower_service::Service<Request> {}