rust-lang / futures-rs

Zero-cost asynchronous programming in Rust
https://rust-lang.github.io/futures-rs/
Apache License 2.0
5.41k stars 626 forks source link

Error on OSX by futures-executir #2827

Closed flashpixx closed 8 months ago

flashpixx commented 8 months ago

Hello,

I try to use NATS-By-Example and it need futures as dependency. So I build a minimal example but on my OSX 14.2 it does not compile:

error: failed to select a version for the requirement `futures-executor = "^0.3.30"`
candidate versions found which didn't match: 0.3.29, 0.3.28, 0.3.27, ...
location searched: crates.io index
required by package `futures v0.3.30`
    ... which satisfies dependency `futures = "^0.3.30"` (locked to 0.3.30) of package `natstest v0.0.0 (/Users/pkraus/Desktop/nats)`
if you are looking for the prerelease package it needs to be specified explicitly
    futures-executor = { version = "0.2.0-beta" }
perhaps a crate was updated and forgotten to be re-vendored?

So my example is:

Cargo.toml

[package]
name = "natsbyexample"
version = "0.0.0"
edition = "2021"
publish = false

[dependencies]
async-nats = {version = "0.33.0", features = ["service"]}
tokio = { version = "1.36.0", features = ["rt", "rt-multi-thread", "macros"] }
serde = { version = "1.0.197", features = ["derive"] }
serde_json = "1.0.114"
futures = "0.3.30"

src/main.rs

use std::env;
use serde_json::json;
use serde::{Deserialize,Serialize};
use futures::stream::StreamExt;

#[derive(Serialize, Deserialize)]
struct Payload {
    foo: String,
    bar: u8,
}

#[tokio::main]
async fn main() -> Result<(), async_nats::Error> {

    let nats_url = env::var("NATS_URL")
        .unwrap_or_else(|_| "nats://localhost:4222".to_string());

    let client = async_nats::connect(nats_url).await?;

    let mut subscriber = client.subscribe("foo").await?.take(2);

    let payload = Payload{foo: "bar".to_string(), bar: 27};
    let bytes = serde_json::to_vec(&json!(payload))?;

    client.publish("foo", bytes.into()).await?;
    client.publish("foo", "not json".into()).await?;

    while let Some(message) = subscriber.next().await {
        if let Ok(payload) = serde_json::from_slice::<Payload>(message.payload.as_ref()) {
            println!("received valid JSON payload: foo={:?} bar={:?}", payload.foo, payload.bar);
        } else {
            println!("received invalid JSON payload: {:?}", message.payload);
        }
    }

    Ok(())
}

But if I add futures-executor = 3.3.30 to my Cargo dependencies, it could be compile, but I'm not sure that the 0.2.0-beta version is correct in relation to the 3.3.0 release. Under Linux it works without the explicit dependency of the future-executor.

Can I get some feedback / help for this issue?

flashpixx commented 8 months ago

sorry mistake post, because it could be solved