hyperium / hyper

An HTTP library for Rust
https://hyper.rs
MIT License
14.57k stars 1.6k forks source link

Make examples usable (TokioIo) #3448

Open inferrna opened 11 months ago

inferrna commented 11 months ago

Currently, one does not simple create own project based on provided examples because almost all examples depends on internal structure TokioIo.

PS: already found TokioIo in hyper-util crate. At least, it should be added to https://github.com/hyperium/hyper/tree/master/examples#dependencies

seanmonstar commented 11 months ago

As mentioned in the hello example, we can't depend on hyper-util in hyper, because then it becomes a cyclical dependency.

Unless we changed the examples to not be a separate crate, instead of natural examples of hyper.

inferrna commented 11 months ago

Ok. Steps to reproduce.

  1. Forget all you know about hyper (If you can't do this, then try next steps on your grandma)
  2. Open examples
  3. Try to make own crate based on any of the examples using the README as a main information source.

I was succeeded after I googled https://hyper.rs/guides/1/client/basic/, and I would do this faster if there wasn't any README in examples folder (I used to trust README files)

BuddhiAbeyratneAL commented 11 months ago

can be closed.

erikschul commented 10 months ago

@seanmonstar If hyper can't be used without the code, then maybe it shouldn't live in a separate hyper_util ?

notgull commented 10 months ago

You can have non-Tokio reactors for Hyper, e.g. https://github.com/notgull/smol-hyper

dswij commented 10 months ago

@seanmonstar If hyper can't be used without the code, then maybe it shouldn't live in a separate hyper_util ?

The whole idea is to allow users to easily choose a reactor for hyper (while also making it independent of tokio). tokio is the one mainly used at the moment, so some common and simple implementations for tokio with hyper are provided in the hyper-util crate instead.

seanmonstar commented 10 months ago

I do agree with the desire for the examples to be immediately usable. Perhaps the best solution is to convert the examples into a crate that's part of the workspace, instead of the crate "examples", and then we can properly depend on hyper-util in there. Is there a downside I'm not thinking off?

dswij commented 10 months ago

@seanmonstar or perhaps we can point users directly to hyper-util crate for examples? with a note saying hyper itself is for a lower-level usecase

thrawn01 commented 5 months ago

What are the objections against exposing support::TokioIo publicly? Having an example which is essentially unusable without depending on a third-party library is very strange, and led to quite a bit of head scratching on my part.

Even though hyper is reactor agnostic, it should have an implementation which works with a rector implementation out of the box. No flexibility is lost, while also allowing new users to Fall into the pit of success

dswij commented 5 months ago

We provided a simple Tokio runtime implementations in hyper-util.

This is not a third-party library, it's maintained by hyper's maintainers.

thrawn01 commented 5 months ago

Thanks, I found it before commenting here. It says This crate is less-stable than hyper, Which doesn't fill me with confidence.

Should we consider it stable and safe to use with hyper 1.0?

dswij commented 5 months ago

It is safe to use with hyper 1.0.