1
votes

I have a struct of memory (obj) wrapped in an Arc<Mutex>. The Mutex is an improved version of the std::sync::Mutex in the parking_lot crate. I need to deserialize the wrapped object (obj), however, I get an error:

the trait `_IMPL_DESERIALIZE_FOR_SecurityLevel::_serde::Deserialize<'_>` is not implemented for `lock_api::mutex::Mutex<parking_lot::raw_mutex::RawMutex, Obj>`

In my Cargo.toml, I have (notably):

serde = { version = "1.0.89", features = ["rc"] }
parking_lot = {version = "0.8", features = ["nightly"]}

How should I go about this? Is there a workaround, or must I manually implement the traits?

1
Please review how to create a minimal reproducible example and then edit your question to include it. We cannot tell what crates (and their versions), types, traits, fields, etc. are present in the code. Try to reproduce your error on the Rust Playground if possible, otherwise in a brand new Cargo project. There are Rust-specific MCVE tips you can use to reduce your original code for posting here. - Shepmaster

1 Answers

3
votes

Support for Serde was added to parking_lot 0.8 under the serde feature flag:

parking_lot = { version = "0.8", features = ["nightly", "serde"] }

Using this, the code you have provided compiles. This also compiles:

use parking_lot::Mutex;
use serde::{Deserialize, Serialize};

fn implements<T>()
where
    Mutex<T>: for<'a> Deserialize<'a> + Serialize,
{
}