Commit 878b10f
authored
util: unify and rename combinators (#499)
Currently, the `ServiceExt` trait has `with` and `try_with` methods for
composing a `Service` with functions that modify the request type, and
`map_err` and `map_ok` methods for composing a service with functions
that modify the response type. Meanwhile, `ServiceBuilder` has
`map_request` for composing a service with a request mapping function,
and `map_response` for composing a service with a response-mapping
function. These combinators are very similar in purpose, but are
implemented using different middleware types that essentially duplicate
the same behavior.
Before releasing 0.4, we should probably unify these APIs. In
particular, it would be good to de-duplicate the middleware service
types, and to unify the naming.
This commit makes the following changes:
- Rename the `ServiceExt::with` and `ServiceExt::try_with` combinators
to `map_request` and `try_map_request`
- Rename the `ServiceExt::map_ok` combinator to `map_response`
- Unify the `ServiceBuilder::map_request` and `ServiceExt::map_request`
combinators to use the same `Service` type
- Unify the `ServiceBuilder::map_response` and
`ServiceExt::map_response` combinators to use the same `Service` type
- Unify the `ServiceBuilder::map_err` and `ServiceExt::map_err`
combinators to use the same `Service` type
- Only take `FnOnce + Clone` when in response/err combinators, which
require cloning into the future type. `MapRequest` and `TryMapRequest`
now take `FnMut(Request)`s and don't clone them every time they're
called
- Reexport future types for combinators where it makes sense.
- Add a `try_map_request` method to `ServiceBuilder`
Closes #498
Signed-off-by: Eliza Weisman <[email protected]>1 parent 0100800 commit 878b10f
File tree
10 files changed
+173
-336
lines changed- tower/src
- builder
- util
- map
10 files changed
+173
-336
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
197 | 197 | | |
198 | 198 | | |
199 | 199 | | |
200 | | - | |
| 200 | + | |
201 | 201 | | |
202 | 202 | | |
203 | 203 | | |
204 | 204 | | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
205 | 217 | | |
206 | 218 | | |
207 | 219 | | |
| |||
211 | 223 | | |
212 | 224 | | |
213 | 225 | | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
214 | 232 | | |
215 | 233 | | |
216 | 234 | | |
| |||
This file was deleted.
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
6 | 9 | | |
7 | 10 | | |
8 | 11 | | |
| |||
12 | 15 | | |
13 | 16 | | |
14 | 17 | | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
15 | 26 | | |
16 | 27 | | |
17 | 28 | | |
| |||
26 | 37 | | |
27 | 38 | | |
28 | 39 | | |
29 | | - | |
| 40 | + | |
30 | 41 | | |
| 42 | + | |
31 | 43 | | |
32 | 44 | | |
33 | 45 | | |
34 | 46 | | |
| 47 | + | |
35 | 48 | | |
36 | 49 | | |
37 | 50 | | |
38 | 51 | | |
39 | 52 | | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | 53 | | |
49 | 54 | | |
50 | 55 | | |
| |||
This file was deleted.
0 commit comments