Futures parking lot quantum weirdness

Ideally, I'd like to be able to return a RwLockWrite/ReadGuard, but there is a type conflict. E.g:

    pub async fn read(&self) -> lock_api::RwLockReadGuard<'_, future_parking_lot::rwlock::FutureRawRwLock<parking_lot::RawRwLock>, NetworkAccountInner> {

    pub async fn write(&self) -> lock_api::RwLockWriteGuard<'_, future_parking_lot::rwlock::FutureRawRwLock<parking_lot::RawRwLock>, NetworkAccountInner> {

The compile error:

error[E0308]: mismatched types
   --> hyxe_user\src\network_account.rs:270:9
270 |         self.inner.future_read().await
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected struct `parking_lot::raw_rwlock::RawRwLock`, found a different struct `parking_lot::raw_rwlock::RawRwLock`
    = note: expected struct `lock_api::rwlock::RwLockReadGuard<'_, future_parking_lot::rwlock::FutureRawRwLock<parking_lot::raw_rwlock::RawRwLock>, _>` (struct `parking_lot::raw_rwlock::RawRwLock`)
               found struct `lock_api::rwlock::RwLockReadGuard<'_, future_parking_lot::rwlock::FutureRawRwLock<parking_lot::raw_rwlock::RawRwLock>, _>` (struct `parking_lot::raw_rwlock::RawRwLock`)
    = note: perhaps two different versions of crate `parking_lot` are being used?

I am using parking_lot, futures-parking_lot, and lock_api. I should only need futures-parking_lot, but I keep getting type errors and have been forced to eventually use all 3 crates just to satisfy a return type. Yet, it still doesn't work. What's happening here?


I don't think you are supposed to mix these libraries. lock_api and parking_lot look like different implementations of a blocking RwLock. While futures-parking_lot is an async RwLock. What is the larger context? What problem are you trying to solve?

1 Like

I literally just want the read() and write() functions above for futures-parking_lot

Whenever you see an error like

where the compiler says "expected X but found X", pay attention to the following note:

Check that all the transitively depended-on versions of parking_lot are the same, and that should help resolve the issue.

futures-parking_lot's most recently published version uses parking_lot v0.9.0, whereas the most recent version of parking_lot is v0.10.0. Make sure that you're using v0.9.0 to avoid the version mismatch.

The current unpublished version of futures-parking_lot works with parking_lot v0.10.0, and re-exports parking_lot as futures-parking_lot::parking_lot to avoid just this issue. (Perhaps you should ask for it to be published? Or just depend on it straight from git.)


As per @CAD97

in Cargo.toml:

future-parking_lot = { git = "https://github.com/nappa85/future-parking_lot" }

And import these wherever you plan on using RwLock:

use future_parking_lot::rwlock::{RwLock, FutureRawRwLock, FutureReadable, FutureWriteable};
use future_parking_lot::parking_lot::lock_api::{RwLockReadGuard, RwLockWriteGuard};
use future_parking_lot::parking_lot::RawRwLock;

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.