Reputation: 23
I come from a Java background, and I am using the hyper library to build an HTTP proxy. So I added hyper
and tokio
to Cargo.toml. I was following the http_proxy example, but first I had to add http
and futures-util
to Cargo.toml. Otherwise, rustc reported an error.
error[E0433]: failed to resolve: use of undeclared crate or module http
The hyper
crate depends on http
, so it means the dependency in cargo can't be shared to my project?
But I see the http 0.2.3
in Clion's External Libraries
list. In a Java project built by Maven, the dependency can be shared from jar to my project, So I can use it directly.
Upvotes: 2
Views: 534
Reputation: 42197
The hyper crate depends on http, so it means the dependency in cargo can't be shared to my project? But I see the http 0.2.3 in Clion's External Libraries list. In a Java project built by Maven, the dependency can be shared from jar to my project, So I can use it directly.
That's correct. You can only use declared direct dependencies: indirect dependencies can't be assumed to be part of the direct dependency's API, so they could be removed in any minor update, breaking semver guarantees.
However there are cases where the direct dependency will re-export part of its own dependency (or even the underlying dependency in its entirety), as "E_net4 with 20k" links that seems to be the case for hyper
which re-exports parts of http
. If what Hyper re-exports does not suffice for your use case, then yes you will have to add an explicit dependency on http
to access what you need beyond that.
Upvotes: 1