lipanski / mockito

HTTP mocking for Rust!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

no function or associated item named `const_new`

sbfaulkner opened this issue · comments

Using mockito 1.3.0 via cargo.toml...

mockito = "1.3.0"

I get...

error[E0599]: no function or associated item named `const_new` found for struct `Semaphore` in the current scope
   --> /Users/sbfaulkner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/mockito-1.3.0/src/server_pool.rs:61:35
    |
61  |             semaphore: Semaphore::const_new(max_size),
    |                                   ^^^^^^^^^ function or associated item not found in `Semaphore`
    |
note: if you're trying to build a new `Semaphore`, consider using `Semaphore::new` which returns `Semaphore`
   --> /Users/sbfaulkner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.25.0/src/sync/semaphore.rs:135:5
    |
135 |     pub fn new(permits: usize) -> Self {
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

I'm not much a a rustacean, but I think it's because of efc7da1

@sbfaulkner which Rust version are you using? could you share your Cargo.toml or at least the portions where you include tokio & mockito? or, even better, some code/repo to reproduce this?

no explicit tokio dependency...

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

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
clap = { version = "4.5.1", features = ["derive", "env"] }
env_logger = "0.10.2"
log = "0.4.20"
mockito = "1.3.0"
reqwest = { version = "0.11.24", features = ["blocking", "json"] }
serde = { version = "1.0.197", features = ["serde_derive"] }
serde_json = "1.0.114"
time = { version = "0.3.34", features = ["serde", "serde-well-known"] }
tungstenite = { version = "0.21.0", features = ["native-tls"] }
url = "2.5.0"

[features]
default = ["cloudflare_logpush"]
cloudflare_graphql = []
cloudflare_post = []
cloudflare_logpush = ["cloudflare_post"]

[[bin]]
name = "cflog"
required-features = ["cloudflare_logpush"]
➜ rustc -V
rustc 1.76.0 (07dca489a 2024-02-04) (Homebrew)

@sbfaulkner Actually I think I know what the problem is: you're using Tokio 1.25 which enables Semaphore::const_new under the parking_lot feature flag (+ the sync feature flag for Semaphores). As of Tokio 1.30 the parking_lot feature flag was dropped so you only need sync (which Mockito enables).

I think you have two options: either upgrade to Tokio 1.30 or try and include the parking_lot feature flag when enabling Tokio (not sure if the latter will work given that Mockito doesn't enable it).

I'll either add a requirement for Tokio 1.30 in Mockito or include the parking_lot feature.

@sbfaulkner Added the feature in 46078db

Can you try Mockito 1.3.1 and let me know if it works?

👍 I will try that.

fwiw, adding the explicit tokio dependency did resolve it too...

+tokio = { version = "1.30.0", features = ["sync"] }

and, yes 1.3.1 fixed it too 👍 Thanks!

- mockito = "1.3.0"
+ mockito = "1.3.1"