docs(service): add example of impl Service (#2209)

Add `examples/service_struct_impl.rs`, which provides an up-to-date
example of implementing MakeService and Service on custom types.
The `Svc` struct has a Counter, which demonstrates how to instantiate
shared resources in the `MakeSvc` and pass the resource to the
services. Updates the `examples/README.md` and the doc in
`src/service/mod.rs`.

Closes #1691
This commit is contained in:
Thomas
2020-06-15 12:01:04 -07:00
committed by GitHub
parent 0d0d363547
commit 55ba000746
3 changed files with 81 additions and 2 deletions

View File

@@ -41,6 +41,8 @@ pretty_env_logger = "0.4"
* [`send_file`](send_file.rs) - A server that sends back content of files using tokio-util to read the files asynchronously.
* [`service_struct_impl`](service_struct_impl.rs) - A struct that manually implements the `Service` trait and uses a shared counter across requests.
* [`single_threaded`](single_threaded.rs) - A server only running on 1 thread, so it can make use of `!Send` app state (like an `Rc` counter).
* [`state`](state.rs) - A webserver showing basic state sharing among requests. A counter is shared, incremented for every request, and every response is sent the last count.