12 Commits

Author SHA1 Message Date
Dongpo Liu
0f0b6ed3ac docs(examples): replace unwraps with expects explaining why (#4001)
Just avoid unwrap as much as possible. Use expect to assert that it will always succeed.

Closes #3984
2026-01-12 15:28:42 -05:00
Maxwell Borden
c62ea805b5 docs(example): remove incorrect comment in example (#3656)
There was a comment in the service_struct_impl.rs example indicating
that the default match arm would somehow return a 404 and not increment
the counter. This wasn't the case. That arm also had a redundant return.
2024-05-03 17:20:44 -04:00
19年梦醒
26f8675293 docs(examples): use share data in service (#3503) 2023-12-26 00:08:42 +00:00
Sean McArthur
f9f65b7aa6 feat(rt): replace IO traits with hyper::rt ones (#3230)
This replaces the usage of `tokio::io::{AsyncRead, AsyncWrite}` in hyper's public API with new traits in the `hyper::rt` module.

Closes #3110

BREAKING CHANGE: Any IO transport type provided must not implement `hyper::rt::{Read, Write}` instead of
  `tokio::io` traits. You can grab a helper type from `hyper-util` to wrap Tokio types, or implement the traits yourself,
  if it's a custom type.
2023-07-10 14:11:06 -04:00
rob2244
d894439e00 feat(service): change Service::call to take &self (#3223)
change Service::call to take &self instead of &mut self.
Because of this change, the trait bound in the service::util::service_fn and
the trait bound in the impl for the ServiceFn struct were changed from FnMut to Fn.
This change was decided on for the following reasons:
- It prepares the way for async fn,
  since then the future only borrows &self, and thus a Service can concurrently handle
  multiple outstanding requests at once.
- It's clearer that Services can likely be cloned
- To share state across clones you generally need Arc<Mutex<_>>
  that means you're not really using the &mut self and could do with a &self

Closes #3040

BREAKING CHANGE: The Service::call function no longer takes a mutable reference to self.
  The FnMut trait bound on the service::util::service_fn function and the trait bound
  on the impl for the ServiceFn struct were changed from FnMut to Fn.
2023-05-15 15:20:34 -04:00
Sean McArthur
95a153bbc2 feat(body): rename Recv to Incoming (#3022)
The concrete "recv stream" body type is renamed to `Incoming`.

Closes #2971
2022-10-25 16:27:17 -04:00
Sean McArthur
0766d3f78d feat(server): remove server::conn::{Http, Connection} types (#3013)
The connection types have been split into version-specific types, in the
`server::conn::{http1, http2}` modules.

Closes #3012

BREAKING CHANGE: Either choose a version-specific `Connection` type, or
  look for the auto-version type in `hyper-util`.
2022-10-17 13:23:47 -04:00
Tom Karwowski
fee7d361c2 feat(service): create own Service trait (#2920)
This removes the dependency on `tower-service`, and simplifies the `Service` trait to be used by hyper's server connections.

Closes #2853 

BREAKING CHANGE: Change any manual `impl tower::Service` to implement `hyper::service::Service` instead. The `poll_ready` method has been removed.
2022-09-08 15:25:20 -07:00
Michael J Ward
7a41da5f60 refactor(body): rename Body to Recv temporarily (#2966)
"""
We'll eventually want to bikshed the name Recv, but to free up the name Body for #2839, this can be done quickly.
"""

Closes #2963
2022-08-26 08:47:14 -07:00
Sean McArthur
9e8fc8fca1 feat(body): remove "full" constructors from Body (#2958)
The constructors of `hyper::Body` from a full bytes are removed. Along
with `Body::empty()`.

BREAKING CHANGE: Use the types from `http-body-util`.

Co-authored-by: Xuanwo <github@xuanwo.io>
2022-08-24 13:01:26 -07:00
Sean McArthur
0c8ee93d7f feat(client,server): remove tcp feature and code (#2929)
This removes the `tcp` feature from hyper's `Cargo.toml`, and the code it enabled:

- `HttpConnector`
- `GaiResolver`
- `AddrStream`

And parts of `Client` and `Server` that used those types. Alternatives will be available in the `hyper-util` crate.

Closes #2856 
Co-authored-by: MrGunflame <mrgunflame@protonmail.com>
2022-07-29 10:07:09 -07:00
Thomas
55ba000746 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
2020-06-15 12:01:04 -07:00