Follow

Why isn't hyper's Service ensuring the poll_ready invariant with typing?

Docs (docs.rs/hyper/0.14.18/hyper/se) say that the user is supposed to wait until poll_ready returns Ready(Ok()) with calling call. Why not instead have poll_ready return Poll<SomeType, Error> and have `call` be a function on SomeType (that takes it by value and consumes it)?

@robryk I think I've found the answer in this issue discussion: github.com/tower-rs/tower/issu. Looks like tower maintainers have no bandwidth for this change and would like to use GATs for implementation anway.

BTW, I've been seeing quite a few concerns related to stabilizing GATs in their current form recently (see e.g. here: github.com/rust-lang/rust/pull), so they might be further off than initially expected.

@krzyz Ah, a thing I was missing was that `call` wants mutable access to Service. Thus, if we wanted to make `call` a method on the token, we'd need to have the token borrow the service mutably. However, that we cannot do: the token appears as a result of the future sometime in an uncertain future. So, we need to have call take both a &mut Service and the token, which sort-of requires the ability to have the type system enforce that we use the token with the service it came from.

I see why this doesn't work straightforwardly, but I don't see why GATs solve this issue and what does the issue have to do with behaviour on dropping.

Sign in to participate in the conversation
Qoto Mastodon

QOTO: Question Others to Teach Ourselves
An inclusive, Academic Freedom, instance
All cultures welcome.
Hate speech and harassment strictly forbidden.