-
Notifications
You must be signed in to change notification settings - Fork 282
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
service: Impl
Service
for async
functions
This PR just a proposal, hence being a draft, but I think its something we should at least consider for tower-service 1.0. The idea is to remove the blanket `Service` impls for `&mut S` and `Box<S>` and replace them with an impl for `F where FnMut(Request) -> Future<Output = Result<Response, Error>>`, and then remove `service_fn`. I personally think and impl for async fns is more valuable mainly to hammer home the "services are just async fns" line. I haven't yet encountered any actual need for the previous impls. `Ready` was the only thing in tower that used it and it could be easily changed to not require them. If we decide to do this I think we should consider doing the same for `Layer`, i.e. remove `impl Layer for &'a L` and make `Fn(S) -> S2` impl `Layer`. This came out of some talk in #650.
- Loading branch information
1 parent
e4e4409
commit 5327f0d
Showing
9 changed files
with
41 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,11 @@ | ||
use futures_util::future::ready; | ||
use tower::util::service_fn; | ||
use tower_service::Service; | ||
|
||
#[tokio::test(flavor = "current_thread")] | ||
async fn simple() { | ||
let _t = super::support::trace_init(); | ||
|
||
let mut add_one = service_fn(|req| ready(Ok::<_, ()>(req + 1))); | ||
let mut add_one = |req| ready(Ok::<_, ()>(req + 1)); | ||
let answer = add_one.call(1).await.unwrap(); | ||
assert_eq!(answer, 2); | ||
} |