How should I use dependencies of dependencies?

Viewed 536

I'm working on project using warp. Warp includes the bytes cargo as a dependency and I want to use the Bytes struct that gets passed into the callback. Here's an example:

use warp::Filter;

fn process(data: bytes::Bytes) -> impl warp::reply::Reply {
    println!("{:?}", data);
    "processed!"
}

#[tokio::main]
async fn main() {
    let process = warp::path("process")
        .and(warp::post())
        .and(warp::body::bytes())
        .map(process);

    warp::serve(process)
        .run(([127, 0, 0, 1], 3030))
        .await;
}

Here's the dependencies in my Cargo.toml:

[dependencies]
bytes = "*"
tokio = { version = "0.2", features = ["full"] }
warp = "0.2"

This setup gives me this error:

error[E0631]: type mismatch in function arguments
  --> src/main.rs:13:14
   |
3  | fn process(data: bytes::Bytes) -> impl warp::reply::Reply {
   | --------------------------------------------------------- found signature of `fn(bytes::bytes::Bytes) -> _`
...
13 |         .map(process);
   |              ^^^^^^^ expected signature of `fn(bytes::bytes::Bytes) -> _`
   |
   = note: required because of the requirements on the impl of `warp::generic::Func<(bytes::bytes::Bytes,)>` for `fn(bytes::bytes::Bytes) -> impl warp::reply::Reply {process}`

Not a big fan of this error message because it's telling me that it's looking for the signature fn(bytes::bytes::Bytes) -> _ and it found fn(bytes::bytes::Bytes) -> _ which pretty much look exactly the same to me, but after some searching I realized it's because there's two different versions of Bytes getting pulled in, so I adjust my Cargo.toml like this:

bytes = "0.5.6"

So I get the same version of bytes that warp is pulling in.

Is this the conventional way to deal with this issue?

0 Answers
Related