softprops / hyperlocal

🔌 ✨rustlang hyper bindings for local unix domain sockets
MIT License
230 stars 46 forks source link

Client example not working: could not find `client` in `hyper_util #74

Closed locnnil closed 2 months ago

locnnil commented 2 months ago

Client example isn't working:

error[E0433]: failed to resolve: could not find `client` in `hyper_util`
   --> src/main.rs:148:17
    |
148 | use hyper_util::client::legacy::Client;
    |                 ^^^^^^ could not find `client` in `hyper_util`

Cargo.toml file:

[package]
name = "env-exporter"
version = "0.1.0"
edition = "2021"

[dependencies]
http-body-util = "0.1.2"
hyper = { version = "1.3", features = ["client"] }
hyper-util = "0.1.6"
hyperlocal = "0.7"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
tokio = { version = "1.35", features = ["full"] }

[profile.release]
panic = "abort"
strip = true
opt-level = "z"
lto = true
codegen-units = 1

rustup toolchain: x86_64-unknown-linux-musl

iamjpotts commented 2 months ago

What version of hyperlocal are you trying to build with - current main?

Can you add some more context for reproducing this?

locnnil commented 2 months ago

@iamjpotts Sure, added in the description.

iamjpotts commented 2 months ago

Version 0.7 of hyperlocal should be considered unsupported at this point. Version 0.8 - which is still using 0.14 versions of hyper - is the latest published version.

If you want to use it with hyper 1.x (e.g. hyper 1.3), you'll need to setup your Cargo.toml to point at this repository for its hyperlocal dependency instead of using a version which would only be able to use versions published to crates.io.

locnnil commented 2 months ago

@iamjpotts thanks for letting me know!

Now with the dependency on Cargo.toml like this:

[dependencies]
http-body-util = "0.1.2"
hyper = { version = "1.3", features = ["client"] }
hyper-util = "0.1.6"
hyperlocal = {git = "https://github.com/softprops/hyperlocal", branch = "main"}
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
tokio = { version = "1.35", features = ["full"] }

I'm having this error:

error[E0599]: no function or associated item named `unix` found for struct `Client` in the current scope
   --> src/main.rs:157:62
    |
157 |     let client: Client<UnixConnector, Full<Bytes>> = Client::unix();
    |                                                              ^^^^ function or associated item not found in `Client<_, _>`

Any idea on how to fix it? Thank you for your help, I appreciate it.

iamjpotts commented 2 months ago

I cannot reproduce your error.

I:

  1. Ran cargo new foo to create a new application crate
  2. Replaced the generated Cargo.toml witih the below snippet
  3. Replaced the generated src/main.rs with the contents of examples/client.rs
  4. From inside foo/ ran both cargo b and cargo b --release

Cargo.toml:

[package]
name = "foo"
version = "0.1.0"
edition = "2021"

[dependencies]
http-body-util = "0.1.2"
hyper = { version = "1.3", features = ["client"] }
hyper-util = "0.1.6"
hyperlocal = {git = "https://github.com/softprops/hyperlocal", branch = "main"}
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
tokio = { version = "1.35", features = ["full"] }

[profile.release]
panic = "abort"
strip = true
opt-level = "z"
lto = true
codegen-units = 1
$ rustc --version
rustc 1.78.0 (9b00956e5 2024-04-29)

Perhaps you could post a gist or a new public repo that reproduces this failure?

locnnil commented 2 months ago

@iamjpotts I just saw the error, I was adding mistakenly a new use that had a wrong path. Now the example compiles.

But basically, at this point, only by reference to the hyperlocal pointing to the main branch of this repository make it work.

iamjpotts commented 2 months ago

Glad to hear you figured it out!

Having to reference the repo's main branch rather than crates.io is expected when used with hyper 1.x as the version of hyperlocal supporting it is not published there yet.

locnnil commented 2 months ago

Thank you very much! I think that this issue can be considered closed!