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

@@ -21,8 +21,9 @@
//! to a single connection. It defines how to respond to **all** requests that
//! connection will receive.
//!
//! While it's possible to implement `Service` for a type manually, the helper
//! [`service_fn`](service_fn) should be sufficient for most cases.
//! The helper [`service_fn`](service_fn) should be sufficient for most cases, but
//! if you need to implement `Service` for a type manually, you can follow the example
//! in `service_struct_impl.rs`.
//!
//! # MakeService
//!